Windows 上的 PHP PDO 安装 (xampp)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18224729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:12:21  来源:igfitidea点击:

PHP PDO installation on windows (xampp)

phporaclepdosybase

提问by Constantinos

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.

我正在尝试开发一个 Web 应用程序,该应用程序可以在 PHP 上连接到尽可能多的不同数据库。PDO ( http://www.php.net/manual/en/book.pdo.php) 似乎是它的正确界面,但我无法安装我需要的所有不同 PDO 数据库驱动程序所需的所有扩展.

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

请注意,我在 Windows 7 机器上使用 xampp。PHP 版本 5.3.8。PDO 驱动程序启用 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)])
  • (已解决,请参阅下面的更新)Sybase(我尝试使用并安装PDO_DBLIB[MS SQL Server (PDO)] 但没有运气)
  • (已解决,请参阅下面的更新)Oracle(我尝试在 php.ini 中启用 extension=php_pdo_oci.dll,并在重新启动 Apache 后使用 xampp 安装的 dll 启用服务器无法启动。正在尝试使用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.

我知道我可以使用特定于数据库的驱动程序来解决这两个问题,但我真的很想将 PDO 用于我需要的一切。

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

有谁知道如何安装和启用PDO_DBLIBPDO_OCI驱动程序或 Windows 机器,或使用 PDO 连接 Sybase 和 Oracle 数据库的任何其他方式?



UPDATE

更新

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

刚刚通过PDO_OCIoracle成功连接。您需要做的是:

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:

在您的 Windows 机器上下载并安装适当的 Oracle Instant Client,例如 instantclient_12_1,并将其路径添加到系统环境变量中的 PATH。注意 Oracle 仅支持 2 个版本,因此请正确选择您的客户端版本。这样做然后重新启动你的Apache。请注意,连接字符串与这里有很大不同,这是我使用的示例:

$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 Sybaseas well with PDO_ODBC. What you need is the following:

刚刚与Sybase以及PDO_ODBC 连接。您需要的是以下内容:

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

必须有 SDK 附带的 Sybase ASE ODBC 驱动程序。在下面找到使用的连接字符串:

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

采纳答案by Constantinos

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

所以我终于设法连接到四个数据库,这是我的管理方式:



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

使用PDO_MYSQL扩展的MySQL似乎默认安装在 xampp 上,不需要做太多工作。这是我用于连接的代码:

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


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

使用PDO_SQLSRV 的Microsoft SQL Server遵循http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/上的说明。这是我使用的代码:

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


Oraclewith 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:

带有PDO_OCI 的Oracle。在您的 Windows 机器上下载并安装适当的 Oracle Instant Client,例如 instantclient_12_1,并将其路径添加到系统环境变量中的 PATH。注意 Oracle 仅支持 2 个版本,因此请正确选择您的客户端版本。这样做然后重新启动你的Apache。这是我使用的代码:

$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);  


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

带有PDO_ODBC 的Sybase必须有 SDK 附带的 Sybase ASE ODBC 驱动程序。这是我使用的代码:

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