I'm trying to for a new PDO connection using the following code.
我正在尝试使用以下代码建立一个新的PDO连接。
new PDO("mssql:driver=????;Server={$serverName};Database={$databaseName}", $username, $password, array(PDO::ATTR_PERSISTENT => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
I'm not sure what drivers to use? or how to install them. I can connect perfectly fine using the mssql_connect function in PHP but I'm wanting to use the PDO library instead.
我不知道该用什么驱动程序?或者如何安装它们。我可以很好地使用PHP中的mssql_connect函数进行连接,但是我想使用PDO库。
Please let me know if you have an ideas on how to either solve my issue or how I can word my question better?
如果你对如何解决我的问题或者我如何能更好地表达我的问题有什么想法,请告诉我。
My php.ini settings for mssql are:
我的php。mssql的ini设置为:
ssql
ssql
MSSQL Support enabled
Active Persistent Links 0
Active Links 1
Library version FreeTDS
MSSQL支持启用活动持久链接0活动链接1库版本freetd。
Directive Local Value Master Value
mssql.allow_persistent On On
mssql.batchsize 0 0
mssql.charset no value no value
mssql.compatability_mode Off Off
mssql.connect_timeout 5 5
mssql.datetimeconvert On On
mssql.max_links Unlimited Unlimited
mssql.max_persistent Unlimited Unlimited
mssql.max_procs Unlimited Unlimited
mssql.min_error_severity 10 10
mssql.min_message_severity 10 10
mssql.secure_connection Off Off
mssql.textlimit Server default Server default
mssql.textsize Server default Server default
mssql.timeout 60 60
指令本地值主值mssql。allow_persistent在该软件。batchsize 0 0该软件。在mssql上关闭charno值没有值mssql.compatability_mode。connect_timeout 5 5该软件。datetimeconvert在该软件。max_links无限无限的该软件。max_persistent无限无限的该软件。max_procs无限无限的该软件。min_error_severity 10 10该软件。min_message_severity 10 10该软件。secure_connection关闭该软件。默认服务器默认的mssql。textsize服务器默认的mssql。超时60 60
Thanks
谢谢
3 个解决方案
#1
30
The PDO mssql driver is no more, use sqlsrv
(under php windows) or dblib
(under php linux)
PDO mssql驱动不再存在,使用sqlsrv(在php windows下)或dblib(在php linux下)
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
http://www.php.net/manual/en/ref.pdo-dblib.php
http://www.php.net/manual/en/ref.pdo-dblib.php
#2
4
I am running Ubuntu 14.04. Trying to connect to MSSQL I got "Uncaught exception 'PDOException' with message 'could not find driver'". It seems that I was missing the dblib/sybase PHP extension.
我正在运行Ubuntu 14.04。试图连接到MSSQL我得到了“未被捕获的异常的PDOException”,消息“无法找到驱动程序”。看起来我错过了dblib/sybase PHP扩展。
I had to run:
我不得不运行:
sudo apt-get install php5-sybase freetds-common libsybdb5 \
&& sudo apache2ctl restart
Works fine now.
工作好了。
#3
1
Try
试一试
$dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
$hostname may need to be configured as either...
$hostname.':'.$port;
OR
或
$hostname.','.$port;
#1
30
The PDO mssql driver is no more, use sqlsrv
(under php windows) or dblib
(under php linux)
PDO mssql驱动不再存在,使用sqlsrv(在php windows下)或dblib(在php linux下)
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
http://www.php.net/manual/en/ref.pdo-dblib.php
http://www.php.net/manual/en/ref.pdo-dblib.php
#2
4
I am running Ubuntu 14.04. Trying to connect to MSSQL I got "Uncaught exception 'PDOException' with message 'could not find driver'". It seems that I was missing the dblib/sybase PHP extension.
我正在运行Ubuntu 14.04。试图连接到MSSQL我得到了“未被捕获的异常的PDOException”,消息“无法找到驱动程序”。看起来我错过了dblib/sybase PHP扩展。
I had to run:
我不得不运行:
sudo apt-get install php5-sybase freetds-common libsybdb5 \
&& sudo apache2ctl restart
Works fine now.
工作好了。
#3
1
Try
试一试
$dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
$hostname may need to be configured as either...
$hostname.':'.$port;
OR
或
$hostname.','.$port;