Codeigniter 3 Postgresql Driver Error Code - error-handling

Is there a workaround for me to get the error code.
The driver returns empty string for $this->db->error() "code" index,
and it also uses pg_query() to execute that is why it will really not return an error code.

First do you have to install the followin package: php5-pgsql
sudo apt-get install php5-pgsql
then restart apache:
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 start
Now, you setup the file database.php of codeigniter 3
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'tu_usuario',
'password' => 'tu_clave',
'database' => 'tu_base_de_datos',
'dbdriver' => 'postgre',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE,
'port' => 5432,
);
Twitter: #luiscordero29

Related

Laravel queue:work not behaving same as queue:listen

<?php
namespace App\Notifications;
use Illuminate\Notifications\Channels\MailChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Config;
class DynamicEmailChannel extends MailChannel
{
public function send($notifiable, Notification $notification)
{
$service = $notification->service;
$customConfig = [];
$from = [];
if ($service->sender_email && $service->sender_password) {
$customConfig = [
'transport' => 'smtp',
'host' => 'smtp.googlemail.com',
'port' => 587,
'encryption' => 'tls',
'username' => $service->sender_email,
'password' => $service->sender_password,
'timeout' => null,
'auth_mode' => null,
];
$from = [
'address' => $service->sender_email,
'name' => $service->title
];
} else {
$customConfig = [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
];
$from = [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example')
];
}
Config::set('mail.mailers.smtp', $customConfig);
Config::set('mail.from', $from);
app()->forgetInstance('mail.manager');
parent::send($notifiable, $notification);
}
}
this program works when run through php artisan queue:listen but the app()->forgetInstance('mail.manager'); runs only once when run through php artisan queue:work. How do i make it behave as with queue:listen?
I am trying to send mail notifications through credentials saved in database.
If i am not wrong, if i delete the 'mail.manager' serviceInstance, it will create new one when called with latest config. it works the same way for queue:listen but not for queue:work. what am i missing, or not understanding here.
After doing some digging replacing app()->forgetInstance('mail.manager'); with Mail::purge('smtp'); solved the issue.

TinyAuth: Authorization adapter "TinyAuth.Tiny" was not found

Im using CakePHP 3 along with TinyAuth plugin for authorization.
After installing TinyAuth in CakePHP 3.0 with Composer, and enabling it in AppController when I try to log in I get the following error:
Authorization adapter "TinyAuth.Tiny" was not found
This is how I initalize it in AppController:
'authorize' => [
'TinyAuth.Tiny' => [
'roleColumn' => 'role_id',
'rolesTable' => 'Roles',
'multiRole' => true,
'pivotTable' => 'roles_users',
'superAdminRole' => null,
'authorizeByPrefix' => false,
'prefixes' => [],
'allowUser' => false,
'adminPrefix' => null,
'autoClearCache' => true
]
And I load it in bootstrap.php like so:
Plugin::load('TinyAuth', []);
in bootstrap.php try:
Plugin::load('TinyAuth');
or
Plugin::load('TinyAuth', ['autoload' => true]);
Load plugins in cakephp 3

install.php is not being run during installation

My install.php is not being run during installation.I checked everywhere.To be sure,I ran the code in install.php elsewhere and it worked well. But during installation only the install.php is being skipped somehow.My module name is Hotelreservation, hence the code in install.php is as below. Why is there no error display during installation ?
<?php
class Hotelreservation_Installer extends Engine_Package_Installer_Module
{
public function onInstall()
{
$this->_hotelroomsBrowsePage();
parent::onInstall();
}
protected function _hotelroomsBrowsePage()
{
$db = $this->getDb();
// profile page
$page_id = $db->select()
->from('engine4_core_pages', 'page_id')
->where('name = ?', 'hotelreservation_index_browse')
->limit(1)
->query()
->fetchColumn();
if (!$page_id) {
// Insert page
$db->insert('engine4_core_pages', array(
'name' => 'hotelreservation_index_browse',
'displayname' => 'HotelRooms Browse Page',
'title' => 'Browse Rooms',
'description' => 'this page displays rooms',
'custom' => 0,
));
$page_id = $db->lastInsertId();
// Insert main
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'main',
'page_id' => $page_id,
));
$main_id = $db->lastInsertId();
// Insert middle
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'middle',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 2,
));
$middle_id = $db->lastInsertId();
// Insert hotelreservation.browse-menu
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'hotelreservation.browse-menu',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 1,
));
// Insert core content
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'core.content',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 2,
));
// Insert left
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'left',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 3,
));
$left_id = $db->lastInsertId();
}
return $this;
}
}// end class
Did you add info to mainfest file like this in packages array
'callback' => array(
'path' => 'Your path to php file',
'class' => 'Hotelreservation_Installer',
),
I agree with Arif. Check the file manifest.php inside of //settings:
(info of module Album)
'callback' => array(
'path' => 'application/modules/Album/settings/install.php',
'class' => 'Album_Installer',
),
I had this same issue and got it to work.
It turns out that the installer looks in application/packages/module-yourmodule-x.x.x.json first. around line 35 you'll find:
"callback": {
"path": null,
"class": "Engine_Package_Installer_Module",
"priority": 100
},
change that to:
"callback": {
"path": "application/modules/Yourmodule/settings/install.php",
"class": "Yourmodule_Installer",
"priority": 100
},
now, when you run the installer, your install.php will be called.

Select table from a different PostgreSQL schema in Laravel 4

In Laravel 4, how do you use a table from another schema (other than the default schema defined in database.php) to query against?
The L4 docs do not show any sign of being able to do this...
http://laravel.com/docs/database
define another schema config in the connections array
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
'newConnection' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
then just switch to it, per the docs:
$users = DB::connection('foo')->select(...);
the question was: How to use an alternate schema in queries?
the answer was to define another schema, then choose to connect to it.
example:
$schema_conn = DB::connection('{ARRAY_KEY_FOR_OTHER_SCHEMA_CONFIG}');
$query = $schema_conn->where('property', 'value')->get();

configuring database config for live site in codeigniter keep getting 500 internal server error

Im pretty done new to actually setting up sites as a live version, I've only done websites using local host. Im using codeigniter for this one, and i've traced my problem to the model where it loads the database. This makes me think that my database config isn't set up correctly.
The model's function is as follows:
public function register($email, $password, $first_name, $last_name, $gender, $birthday){
$salt = $this->generateSalt();
$password = $this->hash($password, $salt);
$data = array('email' => $email, 'password' => $password, 'salt' => $salt, 'first_name' => $first_name,
"last_name" => $last_name, 'gender' => $gender, "birthday" => $birthday);
$this->load->database();
if($this->db->insert('users', $data)){
$this->loginById($this->db->insert_id());
return true;
}else{
return false;
}
}
And the database config looks like this though I removed the password and username for privacy the username and pass I used are the same as I used to get into phpmyadmin though:
$db['default'] = array(
'dsn' => '',
'hostname' => 'http://130.184.99.114/',
'username' => '',
'password' => '',
'database' => 'meetings',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array()
);
So, how do I need to set this up? I think Im on the right track, but im really new to this, so please explain it in a way I can learn please! :D IF you need any more information please let me know.
The hostname you have listed is incorrect.
It should either be:
'hostname' => '130.184.99.114',
or
'hostname' => 'localhost',
depending on how the server has been set up.
Have you set this up in the /application/config/database.php file, or are you doing it differently? I ask as I see failover => array() in there, which isn't in the default configuration file.