PDOException with message 'SQLSTATE[] (null) (severity 0)'

六眼飞鱼酱① 提交于 2020-01-13 16:55:31

问题


The server I am working on is running php 5.5 and it has FreeTDS dblib installed.

php -v returns;

PHP 5.5.0-dev (cli) (built: Oct 23 2012 15:41:58) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

The build is as such;

Configure Command => './configure' '--with-apxs2=/usr/bin/apxs2' '--enable-track-vars' '--with-mssql' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-zlib-dir=/usr' '--enable-ftp' '--with-gd' '--enable-freetype-4bit-antialias-hack' '--with-config-file-path=/etc' '--enable-calendar' '--with-curl' '--with-curlwrappers' '--enable-exif' '--with-mysql' '--with-ldap' '--with-freetype-dir=/usr' '--enable-sockets' '--with-pdo-mysql' '--enable-soap' '--with-mcrypt' '--with-pdo-dblib' '--with-openssl' '--enable-sysvsem' '--enable-shmop' '--enable-pcntl' '--with-xsl'

I am simply trying to connect to an SQL Server box with the following;

<?php $pdo = new PDO ('dblib:host=fqdn,port;dbname=db', 'usr', 'passwd'); ?>

The output is as follows;

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[] (null) (severity 0)' in /path/to/file.php:17 Stack trace: #0 /path/to/file.php(17): PDO->__construct('dblib:host=fqdn...', 'usr', 'passwd') #1 {main} thrown in /path/to/file.php on line 1

Having done my fair amount of searching the existing stack posts on this, they all relate to bug fixes for PHP since 5.2 RCs, or earlier versions of FreeTDS. Considering this server is 5.5 and with a later version of FreeTDS I wondered if anyone had an answer for this very helpful empty SQL state error message.

Interestingly following the guide to confirming your FreeTDS installation suggests commands which are failing to run for me. I am going to attempt reinstallation of FreeTDS.


回答1:


So, it would appear that it is where you are connecting from which impacts the port form.

When using PHP on a Windows based server, the connection string should be;

<?php $pdo = new PDO ('dblib:host=fqdn,port;dbname=db', 'usr', 'passwd'); ?>

When using PHP on a Linux based server, the connection string should be;

<?php $pdo = new PDO ('dblib:host=fqdn:port;dbname=db', 'usr', 'passwd'); ?>

I had assumed the fqdn/port differences were based on your connection TO and not FROM, situation.

Nevertheless, the error handling of this system this module clearly hasn't been given much thought!



来源:https://stackoverflow.com/questions/19518175/pdoexception-with-message-sqlstate-null-severity-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!