I have two computers, one install windows 7 , another is CentOS 5.8
In CentOS...
I use yum command to install httpd(apache2.2), php5.3.3 and mysql.
- yum install httpd
- yum install php53
- yum install pdo
- yum install php53-mysql
First I check the phpinfo, the pdo, pdo_mysql is success extends,
then I also check php -m in CentOS Terminal , have extend pdo and pdo_mysql, too.
I run same code between windows 7 and CentOS
window success, but centos fail
Two files, db.php and dbtest.php
Here is db.php:
<?php
class DB
{
private $conn;
#### construct ####
public function __construct( $dsn , $db_user , $db_password , $showError = false )
{
try
{
$this->conn = new PDO( $dsn , $db_user , $db_password );
if( $showError ) // set error information show or not.
{
$this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
else
{
$this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
}
$setUtf8 = $this->conn->prepare( 'set names utf8' ); // set encoded by utf8
$setUtf8->execute();
}
catch( PDOException $err )
{
return false;
}
}
}
?>
and here is dbtest.php:
<?php
require_once( "db.php" );
$link_test = new DB( "mysql:dbname=pdotest;port=3306;host=192.168.1.127", "root" , "123456" );
var_dump($link_test);
?>
When dump in windows , the result is:
object(DB)#1 (1) { ["conn":"DB":private]=> object(PDO)#2 (0), { } }
dump in CentOS, the result is:
object(DB)#1 (1) { ["conn":"DB":private]=> NULL }
Can anyone tell me why connect fail in CentOS??
Edit at 2012/10/24 16:10 (Asia/Taipei)
For test many hour, I guess is php pdo have problem...
because in my LAN, I can connect any 3306 port mysql by CentOS Terminal
but in php pdo_mysql class, I can't link any mysql(even CentOS local's mysql )
so...how to check my pdo_mysql extension is operate normally?
PS: Sorry,I have poor English :(