PHP5.4之后的版本mysqlnd被作为默认配置选项,若用mysql_connect和mysqli_connect连会报错:
Fatal error: Uncaught Error: Call to undefined function mysql_connect()
Fatal error: Uncaught Error: Call to undefined function mysqli_connect()
=====
eg:
<?php
$conn=new PDO('mysql:host=localhost;dbname=dbstudents;port=3306','root','root');
if ($conn) echo "连接成功";
else echo "连接失败";
?>
=====
如果遇到报错:Uncaught PDOException: could not find driver
则需要将php.ini中关于php_pdo的注释去掉
如果浏览器根本不报错,则需将php.ini中display_errors = On的注释去掉
=====
附:Eclipse给出的语法
PDO::__construct($dsn, [optional] $username=null, [optional] $passwd=null, [optional] $options=null)
Creates a PDO instance representing a connection to a database
Parameters:
$dsn
[optional] $username
[optional] $passwd
[optional] $options
link
http://www.php.net/manual/en/pdo.construct.php
======