Hi,
I am trying to use PDO to access a SQL Server 2005 Express database. I have added the needed extensions to my php.ini file and restarted Apache. Here is an excerpt from my php.ini file:
extension=php_pdo.dll
extension=php_pdo_mssql.dll
extension=php_pdo_odbc.dll
When I restart Apache, I get no errors, so this must means the DLLs are found and loaded (BTW, I am using PHP 5.1.1).
Now, when I try to create a PDO connection to my database using the following code:
$db = new PDO( "mssql:dbname=mydb;host=D971XB1J\SQLEXPRESS",
$username, $password);(
I get a timeout error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Group\Apache2\htdocs\testpdo.php on line 13
When I try using ODBC directly instead of MSSQL, I get a different error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' in C:\Program Files\Apache Group\Apache2\htdocs\testpdo.php:8 Stack trace: #0 C:\Program Files\Apache Group\Apache2\htdocs\testpdo.php(8): PDO->__construct('odbc:dbname=myd...', 'user', 'password') #1 {main} thrown in C:\Program Files\Apache Group\Apache2\htdocs\testpdo.php on line 8
Does anyone know what the problem can be? I would rather use the MSSQL driver, but would be happy to go for the ODBC one if I can't get it to work.
I have a working web site that uses standard ODBC connection to the SQL Server database (I mention this so you know there is no problem with the server or db themselves). I just want to change the connection to PDO.
Thanks,
Javier