Yii Link PostgreSQL

Source: Internet
Author: User
Tags postgresql yii

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.