PDO problem

Hello
I’m learning to program PHP for the first time, and I’m using a great book called: “PHP & MYSQL NOVICE TO NINJA” written by Kevin Yank.
I have an error and I can’t get around it.
In chapter 4 he introduces a PDO class as a way to connect to a MySql database, but I get an error message that reads:
“Unable to connect to the database server. could not find driver”

Just in case, I downloaded XAMPP version 3.0.12 compiled on June 24, 2012
I’m running Apache and MySql from the XAMPP Control Panel.
They are not installed as services.

I would appreciate any help on this matter.
Thanks

Use phpinfo() to locate what php.ini file you’re using then open that php.ini file open. Look for a line that looks like:

extension=php_pdo_mysql.dll

There’s probably a ; at the start of the line, remove the ; save the changes and then reboot the server.

Thanks for your prompt reply.
This is a partial copy of the php.ini file:

Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

extension=php_bz2.dll
;extension=php_curl.dll
extension=php_mbstring.dll
extension=php_exif.dll
;extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mssql.dll
;extension=php_mbstring.dll
;extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pdo_sqlite_external.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll

; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll

extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll

But when I check the phpinfo.php there is a section “Configure Commands” ( fifth row from the top )
That states the following details:
cscript /nologo configure.js “–enable-snapshot-build” “–disable-isapi” “–enable-debug-pack” “–without-mssql” “–without-pdo-mssql” “–without-pi3web” “–with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared” “–with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared” “–with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared” “–enable-object-out-dir=…/obj/” “–enable-com-dotnet” “–with-mcrypt=static” “–disable-static-analyze” “–with-pgo”

What does that mean?
On php.ini the pdo is activated, but in the phpinfo() it shows as “without-mysql” and “without-pdp-mysql”

Thanks again

As an addition to my last message, I have to add that in the PDO section of the phpinfo(), it shows that the pdo is enabled for mysql and sqlite.
I’m stuck…

Can you paste the code that is invoking this error? Maybe the MySQL Service/Server isn’t running? Or is running on a different port?

Of course !
here is the code:

<?php
try
{
$pdo=new PDO(‘msql:host=localhost;dbname=ijdb’, ‘ijdbuser’, ‘123’);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec(‘SET NAMES “UTF-8”’);
}
catch (PDOException $e)
{
$output='Unable to connect to the database server. ’ .
$e->getMessage();
include ‘output.html.php’;
exit();
}
$output=‘Database connection established!’;
include ‘output.html.php’;
?>

And the message as I wrote before is:
"Unable to connect to the database server. could not find driver "

I double checked and the Apache server is running and the MySQL is also running using the default port 3306

Thanks for your time…

You misspelled mysql in the driver name

$pdo=new PDO('msql:host=localhost;dbname=ijdb', 'ijdbuser', '123');

Should be

$pdo=new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser', '123');

How embarrased I am…!!
Thank you cpradio for pointing this out…

Just after correcting this typo, another error appear.
Something like there is an error with the UTF-8…
But I removed the “-” and leave it at UTF8, and I got the "Database connection established! "

I really appreciate your help.
Thanks

:slight_smile: As you work through the book, if you need any other help, please post another thread. There are several people here who are always willing to help :slight_smile: