php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45294 phpcli and ms sql
Submitted: 2008-06-17 11:13 UTC Modified: 2009-09-03 01:00 UTC
Votes:14
Avg. Score:4.4 ± 0.9
Reproduced:12 of 12 (100.0%)
Same Version:6 (50.0%)
Same OS:4 (33.3%)
From: lowee at lowee dot net Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2.6 OS: windows 2003
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lowee at lowee dot net
New email:
PHP Version: OS:

 

 [2008-06-17 11:13 UTC] lowee at lowee dot net
Description:
------------
php cli with pdo and ms sql
it is working on any web browser but on php cli it is not working 

Reproduce code:
---------------
	define('DB_HOST','192.168.1.20');
	# mtc_awdb
	# mtc_hds
	define('DB_NAME','db1');
	define('DB_USER','user');
	define('DB_PASS','pass');

	$dbhandle = mssql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't connect to SQL Server on");
	try {
	 $pdo = new PDO('mssql:host='.DB_HOST.';dbname='.DB_NAME,DB_USER,DB_PASS);
	}catch (PDOException $e) {
			print $e->getMessage();
		}

Expected result:
----------------
to show me that it is connected


Actual result:
--------------
1 - SQLSTATE[01002] Unable to connect: SQL Server is unavailable or does not exist.
(severity 9)
2 - SERVER not available 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-06 12:05 UTC] jani@php.net
Check what php.ini file is actually loaded. Most likely you're just missing the proper extensions. Then change that script a bit:

<?php

define('DB_HOST','192.168.1.20');
define('DB_NAME','db1');
define('DB_USER','user');
define('DB_PASS','pass');
try {
  $pdo = new PDO('mssql:host='.DB_HOST.'dbname='.DB_NAME,DB_USER,DB_PASS);
}catch (PDOException $e) {
  print $e->getMessage();
}
?>

And post the output here.

 [2008-07-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-07-22 23:32 UTC] kian dot mohageri at gmail dot com
Very similar problem here with pdo_dblib.  Works fine under Apache module, but not CLI.

I've tried to ensure everything was built correctly.

<?php

$user = 'foo';
$pass = 'bar';
$dbh = new PDO('dblib:host=odyssey:2638;dbname=odyssey', $user, $pass);

?>

> php testpdo.php

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] Server is unavailable or does not exist. (severity 9)' in /usr/home/kian/public_html/testpdo.php:5
Stack trace:
#0 /usr/home/kian/public_html/testpdo.php(5): PDO->__construct('dblib:host=odys...', 'foo', 'bar')
#1 {main}
  thrown in /usr/home/kian/public_html/testpdo.php on line 5

> php -v
PHP 5.2.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 22 2008 16:30:13) (DEBUG)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

FreeBSD 7.0.
 [2009-08-26 11:20 UTC] mayurika at conceptinfoway dot net
Same issue with me:
Neither PDO lib is working nor MSSQL

I have tried both  

1) MSSQL: 
try 
		{
			$pdo = new PDO ("mssql:host=".$servername.":".$port.";dbname=".$dbname,$username,$password);
		} 
		catch (PDOException $e)
		{
			echo "Failed to get DB handle: " . $e->getMessage() . "\n";
			exit;
		}

Error is: Failed to get DB handle: could not find driver 
2) PDO-lib

		try 
		{
			$pdo = new PDO ("dblib:host=".$servername.":".$port.";dbname=".$dbname,$username,$password);
		} 
		catch (PDOException $e)
		{
			echo "Failed to get DB handle: " . $e->getMessage() . "\n";
			exit;
		}
Error is: Failed to get DB handle: SQLSTATE[HY000] Server is unavailable or does not exist. (severity 9)
 [2009-08-26 12:27 UTC] pajoye@php.net
If you are on windows, please try a 5.2 snapshot. (http://windows.php.net/snapshots/)
 [2009-09-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC