cannot get PDO working for mysql
Posted: Thu Sep 20, 2007 10:56 am
i got a zip file for php 5.2.4 and used it with apache 2.2.x. i had two problems. one is mysqli would not work with existing php_mysqli.dll and replaced this with php_mysqli.dll for php 5.2.1 from http://www.mysql.com and mysqli started working. for pdo, looks like pdo extensions for other dbs are working but only the mysql is not working.
error:
actual code
full output including messages got from php.ini
part of relevant php.ini settings
error:
Code: Select all
PDOException Object ( [message:protected] => could not find driver [string:private] => [code:protected] => 0 [file:protected] => C:\web\htdocs\phpinfo.php [line:protected] => 25 [trace:private] => Array ( [0] => Array ( [file] => C:\web\htdocs\phpinfo.php [line] => 25 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=localhost [1] => root [2] => .. ) ) ) [errorInfo] => )actual code
Code: Select all
<?php
##print_r( ini_get_all() ); exit;
##echo phpinfo(); exit;
error_reporting( E_ALL );
##ini_set( 'display_errors', 'on' );
##$conn = new mysqli( 'localhost', 'nouser', '' ); $conn->thread_id; exit;
ob_start();
phpinfo();
$matchString = ob_get_contents();
ob_end_clean();
preg_match_all( "#^.*?PDO.*?$#mi", $matchString, $matches );
print_r( $matches );
echo '<br />----------------------------------<br />';
##dl( 'php_pdo_mysql.dll' );
try{
$conn = new PDO( 'mysql:host=localhost', 'root', '..' );
}catch( PDOException $e ){
print_r( $e ); exit;
}
$databasesResult = $conn->query( 'show databases', PDO::FETCH_CLASS );
if( $databasesResult ){
while( $row = $databasesResult->fetch_object() ){ print_r( $row ); }
}
?>
full output including messages got from php.ini
Code: Select all
Array ( [0] => Array ( [0] =>
PDO
[1] => PDO supportenabled [2] => PDO drivers odbc, pgsql, sqlite, sqlite2 [3] =>
PDO_ODBC
[4] => PDO Driver for ODBC (Win32)enabled [5] =>
pdo_pgsql
[6] => PDO Driver for PostgreSQLenabled [7] => Revision $Id: pdo_pgsql.c,v 1.7.2.11.2.1 2007/01/01 09:36:05 sebastian Exp $ [8] =>
pdo_sqlite
[9] => PDO Driver for SQLite 3.xenabled [10] => PECL Module version 1.0.1 $Id: pdo_sqlite.c,v 1.10.2.6.2.2 2007/03/23 14:30:00 wez Exp $ ) )
----------------------------------
PDOException Object ( [message:protected] => could not find driver [string:private] => [code:protected] => 0 [file:protected] => C:\web\htdocs\phpinfo.php [line:protected] => 25 [trace:private] => Array ( [0] => Array ( [file] => C:\web\htdocs\phpinfo.php [line] => 25 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=localhost [1] => root [2] => .. ) ) ) [errorInfo] => )part of relevant php.ini settings
Code: Select all
;extension=php_mssql.dll
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
extension=php_pdo.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll