pdo is the next unified database interface for PHP. The current version is 0.9. It seems that it will be released soon. Let’s try it first.
After testing, pdo connection is about 3 times faster than adodb, which is very different from direct connection.
Test tool: AB
Test conditionsApache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2 PHP/5.0.4-0.10 mod_perl/2.0.1 Perl/v5.8.7 Server at 127.0.0.1 Port 80
Database: postgres8.0.3
Hardware: C4-1.7g;384M
Installing pdo requires PHP's development toolkit and gccg++, and of course PHP's php5-dev is also required.
Installing PDO_pgsql requires libpg-dev or above software and must apt-get otherwise it will fail! ! !
#>pear remote-info pdo
pear remote-info pdo
Notice: Undefined index: name in Remote.php on line 132
Notice: Undefined index: version in Remote.php on line 133
Notice: Undefined index: name in CLI.php on line 443
Notice: Undefined index: license in CLI.php on line 444
Notice: Undefined index: category in CLI.php on line 445
Notice: Undefined index: summary in CLI.php on line 446
Notice: Undefined index: description in CLI.php on line 447
Package details:
================
Latest
Installed-no-
Package
License
Category
Summary
Description
Ha, I still don’t know which version is better. Go to http://pecl.php.net/ to search. The current version is 0.9.
OK
#》pear install pdo-0.9
Pear will help you install the compiled modules and place them in the directory: /usr/lib/php5/20041030/
#>cd /usr/lib/php5/20041030/
Note: The PHP external module of the Debian system requires two files to be started. One is the pdo.so we just compiled.
In addition, you also need a pdo.info file. If you don’t know how to write it, just fry the following:
package="pdo"
extname="PDO"
dsoname="pdo"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
architecture="any"
Then run:
#》/usr/sbin/php5-modconf apache2
The system will prompt you which modules you need, select pdo to confirm
pdo is installed successfully. Now install pdo_pgsql-0.9
This needs to be done according to the following steps:
#》pear download pdo_pgsql-0.9
#> tar zxf PDO_PGSQL-0.9.tgz
#>cd PDO_PGSQL-0.9
#>phpize
#>./configure
#>make
#>make install
Then repeat the above process of installing pdo: modify pdo_pgsql.info
package="pdo_pgsql"
extname="PDO_PGSQL"
dsoname="pdo_pgsql"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
architecture="any"
run
#》/usr/sbin/php5-modconf apache2
Select the pdo_pgsql module
ok everything is ready
#》apache2 -k restart
Edit the test module:
// Connect to an ODBC database using driver invocation
$host='xxxx.xxxx.com';
$port='5433';
$dbname='test';
$user='xxxxxx';
$password='xxxxxxxx';
//$cc = "host=$host,dbname=$dbname,port=$port";
$dsn = "pgsql:host=$host port=$port dbname=$dbname user=$user password=$password";
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql='select * from cpjcsj';
foreach ($dbh->query($sql) as $row) {
print $row['cpdm']."t";
print $row['cpdh'] . "t";
print $row['cpmc'] . "n";
}
?>
Okay, enter http://localhost/pdotest.php in your browser
Do you see the data in your database? Congratulations! ! !