10

I am trying to develop a web app that can connect to as many different databases as possible on PHP. PDO (http://www.php.net/manual/en/book.pdo.php) seems to be the right interface for it but I am having trouble installing all the extentions needed for all the different PDO database drivers that I need.

Please note that I use xampp on a windows 7 machine. PHP Version 5.3.8. PDO drivers enabled mysql, odbc, sqlite, sqlite2, sqlsrv.

I have successfully connected with the following:

I had no luck installing or connecting with:

  • (SOLVED SEE BELOW UPDATES) Sybase (I tried to use and install PDO_DBLIB [MS SQL Server (PDO)]but with no luck)
  • (SOLVED SEE BELOW UPDATES)Oracle (I tried to enable the extension=php_pdo_oci.dll in php.ini with the dll that was installed with xampp after restarting Apache the server failed to start. Was trying to use PDO_OCI [Oracle (PDO)])

I know I can work around those 2 with using the database specific drivers but I would really love to use PDO for everything that I need.

Does anyone know how to install and enable PDO_DBLIB and PDO_OCI drivers or a windows machine, or any other way of connecting with Sybase and Oracle databases using PDO?


UPDATE

Just succesfully connected with oracle with PDO_OCI. What you need to do is the following:

Download and install the proper Oracle Instant Client on your windows machine for example instantclient_12_1 and add its path to PATH in SYSTEM Environmental Variables. Note Oracle supports only 2 versions down so select your client version properly. Do that and then restart your Apache. Note that the connection string is very different from here is a sample of what I used:

$tns = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$myServer.")(PORT = 1521)))(CONNECT_DATA=(SID=".$myDB.")))"; 
$connStr = "oci:dbname=".$tns;      
$conn = new PDO($connStr,$myUser,$myPass);  

UPDATE

Just connected with Sybase as well with PDO_ODBC. What you need is the following:

Must have Sybase ASE ODBC Driver which comes with the SDK. Find below the connection string used:

$connStr = "odbc:Driver={Adaptive Server Enterprise};server=".$myServer.";port=".$myPort.";db=".$myDB;
$conn = new PDO($connStr,$myUser,$myPass);  
4

1 回答 1

3

So i finally managed to connect to four database here's how I managed:


MySQL using PDO_MYSQL extension seemed to be installed on xampp by default didn't have to do much work. Here is the code I used for the connection:

$connStr = "mysql:host=".$myServer.";dbname=".$myDB; 
$conn = new PDO($connStr,$myUser,$myPass);  

Microsoft SQL Server using PDO_SQLSRV followed the instructions on http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/. Here is the code I used:

$connStr = "sqlsrv:Server=".$myServer.";Database=".$myDB; 
$conn = new PDO($connStr,$myUser,$myPass);

Oracle with PDO_OCI. Download and install the proper Oracle Instant Client on your windows machine for example instantclient_12_1 and add its path to PATH in SYSTEM Environmental Variables. Note Oracle supports only 2 versions down so select your client version properly. Do that and then restart your Apache. Here is the code I used:

$tns = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$myServer.")(PORT = 1521)))(CONNECT_DATA=(SID=".$myDB.")))"; 
$connStr = "oci:dbname=".$tns;      
$conn = new PDO($connStr,$myUser,$myPass);  

Sybase with PDO_ODBC Must have Sybase ASE ODBC Driver which comes with the SDK. Here is the code I used:

$connStr = "odbc:Driver={Adaptive Server Enterprise};server=".$myServer.";port=".$myPort.";db=".$myDB;
$conn = new PDO($connStr,$myUser,$myPass);  
于 2013-08-19T21:26:26.200 回答