Ubuntu
Official Website Introduction http://php.net/manual/en/ref.pdo-pgsql.php
Specific steps:
wget http://pecl.php.net/get/PDO_PGSQL-1.0.2.tgz
TAR-ZXVF pdo_pgsql-1.0.2.tgz
cd/download/pdo_pgsql-1.0.2/pdo_pgsql-1.0.2
(if it's not clear where PHP is installed, the simplest way to enter the command directly: Whereis phpize, my Files directory is in/usr/bin/phpize)
Usr/bin/phpize
./configure--with-pdo-pgsql
(Thank Dahuzix for letting me find out./configure path http://blog.csdn.net/dahuzix/article/details/76283871, but does not need to be installed in all of his steps)
Now that the pdo_pgsql.so is installed, configure the configuration file below
sudo vi/etc/php/7.1/cli/php.ini (because I am using a shell script to run the PHP yii serve, so in the CLI directory of php.ini. Use other methods to have the corresponding path at the end of the article)
(Etc folder is a configuration folder, all applications run first through here to view the configuration, so do not configure php.ini elsewhere)
Enter/pgsql in instruction mode to jump to the extension section and add the following code
Extension=pdo.so
Extension=pdo_pgsql.so
At this point the configuration of the running section is good, the following is the Yii section to access the database
Configure the database in the db.php file in the Config directory of the Yii project
return [ ' class ' = ' Yii\db\connection ', ' dsn ' = ' pgsql:host=localhost;port=5432;dbname= Exampledb ', ' username ' = ' dbuser ', ' password ' = ' abc123_ ', ' CharSet ' = ' utf8 ',];
dbname is your database name.
Create the testcontroller.php file in the controller, create an Access test
function actiontest () { = Yii:: $app->db->createcommand ("UPDATE user_tbl SET name = ' TTT ' WHERE id = 999999 1 "); return $test, execute ();}
The test method is used to prove that the linked database is correct, and other modifications to the database
CD to your project directory, run PHP yii serve
Access method in Browser: http://localhost:8080/controllers/test/test
Controllers is the directory where your controller is located, test asks Testcontroller.php, test is the Actiontest () method
Yii Link PostgreSQL