Not able to connect PostgreSQL with Yii - postgresql

I have tried to connect PostgreSQL with Yii but is is showing
CDbConnection failed to open the DB connection.
In log it is showing
error exception.CDbException
could not find driver
My code
'db'=>array(
'tablePrefix'=>'',
'connectionString' => 'pgsql:host=localhost;port=5432;dbname=postgres',
'username'=>'postgres',
'password'=>'postgres',
'charset'=>'UTF8',
),

Yii Database component is build on top of PHP PDO. So Here are list of posibilities to check
Check that PostgreSQL and PostgreSQL's PDO Extension is installed and working. Also that port is right one. You can test simple PHP Script to test.
Below are links to something that might be similar
PostgreSql 'PDOException' with message 'could not find driver'
PDOException “could not find driver”
Install PDO on Linux (Ubuntu/Debian)
Install pdo for postgres Ubuntu
https://serverfault.com/questions/89970/how-to-install-postgresql-extension-for-pdo-in-linux
Windows
http://blog.lysender.com/2010/08/php-and-postgresql-on-windows/
Apache php 5.3 postgreSQL driver could not be loaded
Official PHP Information on Issue
http://php.net/manual/en/pdo.installation.php
http://www.php.net/manual/en/ref.pdo-pgsql.php

Resolved issue...by adding
LoadFile "C:/wamp/bin/php/php5.3.5/libpq.dll"
to httpd.conf file. Now phpinfo() is showing pgsql PDO.
thanks...

if you work in ubuntu make sure that you have installed pgsql library
sudo apt-get install php-pgsql
sudo service apache2 restart
after make sure that in the console and main-local there are this array
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=localhost;port=5432;dbname=yourdb',
'username' => 'user',
'password' => 'pw',
'charset' => 'utf8',
],],

In my case, it was a case of enabling the php_pdo_pgsql extension in WAMP

for those struggling with the same issue i did the work around.
environment
Yii2
server:LAMP stack 7.1
problem Driver not found i.e the "requirements.php" shows warning
"PDO PostgreSQL extension Warning All DB-related classes Required for PostgreSQL database."
i noted that pdo_pgsql.so is not packaged together with bitnami so i search for it online or try locate if installed on any php versions in /usr/lib/php
copy that file to lampstack-7.1.10-1/php/lib/php/extensions.
now go to lampstack php.ini "lampstack-7.1.10-1/php/etc/php.ini"
now place this line "extension=pdo_pgsql.so" remove ; if commented out NB you can point to the absolute path "/usr/lib/php/pdo_pgsql.so" if it existed there
restart Lamp apache server
visit requirement.php and if you see ""PDO PostgreSQL extension Passed All DB-related classes Required for PostgreSQL database.""

Related

How to Install laravel/scout on Lumen with mysql driver?

Steps to install laravel/scout on Lumen framework (there are some additional steps that you need to do to make it work with lumen opposed to Laravel)
First install laravel
composer require laravel/scout
Register the service provider in the bootstrap/app.php in the provider section
$app->register(Laravel\Scout\ScoutServiceProvider::class);
Copy the configuration file (you may be able to do it with composer php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider" , I wasn't)
cp vendor/laravel/scout/config/scout.php config/scout.php
Ask lumen to load the configuration file, adding this line to boostrap/app.php
$app->configure('scout');
Install laravel mysql mysql driver
composer require yab/laravel-scout-mysql-driver
Change the driver setting in config/scout.php
'driver' => env('SCOUT_DRIVER', 'mysql'),
Append this to config/scout.php
'mysql' => [
'mode' => 'NATURAL_LANGUAGE',
'model_directories' => [app_path()],
'min_search_length' => 0,
'min_fulltext_search_length' => 4,
'min_fulltext_search_fallback' => 'LIKE',
'query_expansion' => false
]
run the scout index if plan to use in NATURAL_LANGUAGE or BOOLEAN
php artisan scout:mysql-index
Use like this
Model::search(searchString)->get();
You can also add other conditions
Model::search(searchString)->where(...)->get()
According to the above answer,this line:
'driver' => env('SCOUT_DRIVER', 'mysql'),
cause an error which was "Driver [mysql] not supported".
For solving the problem use "database" instead of "mysql" as a driver.

How to configure memcached in suitecrm Version 7.8.2

I am running Suitecrm 7.8.2 on XAMPP where PHP version is 7. I want to install Memcached on this. Is there any way to configure the Memcached on suitecrm.
Please Help. Thanks in advance.
If its not already in the config.php file, add the following to the config_override.php file, add the following:
'external_cache' =>
array (
'memcached' =>
array (
'host' => '127.0.0.1',
'port' => '11211',
),
),

yii migrate command doesn't work with postgresql database

I installed Yii 2 advanced template. "yii migrate" command in CMD works perfectly with the default MySQL database, it populates the database with the tables migration and user as expected (see step 3 explained here: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md)
But "yii migrate" doesn't work with the postgresql database. It produces following error message:
What's wrong, or what is missing? Data tables can be read by the Yii 2 framework if I create them manually (already tested), but migrate command doesn't want to work.
The required pdo extensions for postgresql are out-commented in the php.ini file. The web page requirements.php shows "passed" (no errors or warnings) for PDO PostgreSQL extension.
My db connection configuration in common/config/main-local.php:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'tablePrefix' => 'tbl_',
'dsn' => 'pgsql:host=localhost;port=5432;dbname=mytestdb',
'username' => 'postgres',
'password' => 'tuparnix',
'charset' => 'utf8',
// see: http://stackoverflow.com/questions/26436024/how-to-set-default-schema-in-yii2
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'public' //specify your schema here
],
], // PostgreSQL
],
Your command line php and your web server php is a different php.
You need to out-comment your postgres driver in command-line php.ini.
Please run these in command line for more info (I'm not sure what is windows version of these command, please chk)
which php
php -i
I have the same problem in Windows but not Linux. Perhaps, that come from driver php_pdo_pgsql + libpq.dll.
Which version you have in your phpinfo (), Postgresql 8.3.3 (windows) or 9.2.1 (linux) that would not be compatible. Looking from this side.
What is the server you are using on Windows? (xampp, easyphp, WampServer) and what version of php (5.4, 5.5, 5.6 ...).

"FATAL: no pg_hba.conf entry for host" but I can connect trough pgAdmin

I'm having a little trouble with my dev environment for a CakePHP based project.
The thing is, CakePHP can connect in production, but if I run trough XAMPP on my PC, then throws me a
FATAL: no pg_hba.conf entry for host "myexternalip", user "dbuser", database "dbname", SSL off
but using the same parameters I can connect from my PC trough pgAdmin.
I've tried some googling tips that I've found like copy the libpq.dll from c:\xampp\php to c:\xampp\apache\bin but, no luck, had checked pnp.ini and extension=php_pdo_pgsql.dll line is uncommented, had tried reboot apache several times but nothing changes
The project is hosted under heroku platform and my /app/config/database.php looks like
public $production = array(
'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => 'anywhere.at.amazonaws.com',
'login' => 'dbuser',
'password' => 'dbpwd',
'database' => 'dbname',
'encoding' => 'utf8',
);
here's the Stack Trace
- CORE\Cake\Model\Datasource\DboSource.php line 260 → Postgres->connect()
- CORE\Cake\Model\ConnectionManager.php line 105 → DboSource->__construct(array)
- CORE\Cake\Model\Model.php line 3613 → ConnectionManager::getDataSource(string)
- CORE\Cake\Model\Model.php line 1155 → Model->setDataSource(string)
- CORE\Cake\Model\Model.php line 3640 → Model->setSource(string)
- CORE\Cake\Model\Model.php line 827 → Model->getDataSource()
Can anyone give me another hint that could help?
After while I found a solution.
The problem is that's not straightforward.
As the Postgres server is hosted under heroku platform, the default configuration on server is require ssl, so I've came across to this configuration:
public $production = array(
......
'sslmode' => 'require',
);
Now the error has changed to a sslmode value "require" invalid when ssl support is not compiled
then I've googled it and seems that at least under XAMPP v5.5.19, the libpq.dll inside PHP folder wasn't compiled with ssl support
here's the question that helped me solve this problem:
How to installPostgreSQL client library for PHP on Windows with SSL enabled
Seems that pgAdmin's libpq.dll was compiled with ssl support, so that is the cause that I could connect through pgAdmin, but not with php
thanks for help folks!

zend framework Connect Error: could not find driver pdo mysql

I have a machine with:
centOS 6.5
php 5.5.7 from remi repository
mysql 5.5.35 from remi repository
i'm triyng to connect zend framework 2 to a mysql database but i getting the following error:
An error occurred
An error occurred during execution; please try again later.
Additional information:
Zend\Db\Adapter\Exception\RuntimeException
File:
/var/www/zf2demo/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Connection.php:289
Message:
Connect Error: could not find driver
According to phpinfo i have the pdo installed and running
PDO support enabled
PDO drivers mysql, sqlite
pdo_mysql
PDO Driver for MySQL enabled
Client API version mysqlnd 5.0.11-dev - 20120503 - $Id: 40933630edef551dfaca71298a83fad8d03d62d4 $
Directive Local Value Master Value
pdo_mysql.default_socket /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock
I already have the extensions pdo.so and pdo_mysql.so in my php.ini file.
my connection is done by (the username and password are at other file):
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=album;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
What can be wrong?
I had the similar problem at CentOS release 6.4 with Zend and PHP 5.4. PDO appears in phpinfo() but mentioned error ("could not find driver") ocurred on all pages related with database. Php 5.4 had included packages php-common, etc. and previous pdo package was obtained from alterantive yum/rpm repository. Maybe your current PDO package also fails.
Finally, in my case the solution was to install other php-pdo package (php54w-pdo.x86_64).
#yum install php54w-pdo.x86_64
I supose that you should install php55w-pdo.x86_64
#yum install php55w-pdo.x86_64
Don't forget restart Apache!