lukeocodes
lukeocodes

Reputation: 1232

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

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.

Upvotes: 3

Views: 6442

Answers (1)

lukeocodes
lukeocodes

Reputation: 1232

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!

Upvotes: 5

Related Questions