Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to MS SQL Server using PEAR::DB ?

Status
Not open for further replies.

MikeBronner

Programmer
May 9, 2001
756
US
Hi guys and gals,
I am trying (in vain it seems) to connect to our SQL server here using PEAR with the following code:
Code:
		public function connect()
		{
			try
			{
				$dsn = $this->_s_type . '://' . $this->_s_username . ':' . $this->_s_password . '@' . $this->_s_server . '/' . $this->_s_database;
				$db = DB::connect($dsn);
				if (PEAR::isError($db)) {throw new Exception($db->getMessage());}
				else
				{
					$this->_r_connection = $db;
					return true;
				}
			}
			catch(exception $error)
			{
				return false;
			}
		}
The values used for the DSN are set in the class constructor . When I run this I get the following error returned from PEAR::DB:
DB Error: connect failed
Eventhough I can connect to the server using the same information via the native PHP function mssql_connect()
$connection = mssql_connect('server', 'username', 'password')
, etc. Any ideas?

Take Care,
Mike
 
try substituting the getDebugInfo() for getMessage(). it provides the native message back from mssql as to why the connect failed.

also try echoing the dsn just to make sure there is nothing bizarre coming through
 
I figured it out. Re-reading the PHP.NET page on mssql I decided to re-copy the ntwdblib.dll from the SQL server. Eventhough I had done this previously, it seems the original got lost (on my dev machine).
All is working now. :)

Take Care,
Mike
 
JPadie,

Thanks for the tip with getDebugInfo(). However, it appears to return the same information as getMessage (using MDB2).

[I decided to upgrade to MDB2 because of huge performance gains.]

Take Care,
Mike
 
it will do so unless the error message is engine specific rather than pear specific. in this case i guess the issue failed at the connect level because the db server wasn't available to the two messages would have been the same.

interesting about mdb2 being faster. is that across all engines? is there any syntactical difference between the two abstraction layers?

the query result from an error contains some interesting data. i've occasionally been able to debug an issue quicker by print_r the entire error variable rather than just the debuginfo or message. you get, for example, the complete query as passed to the engine, even if you used parameters or prepare/execute to build it.
Code:
$res = $db->query("select * from table where id=?", array(3));
if (PEAR::isError($res)):
 echo "<pre>";
 print_r ($res);
 echo "</pre>";
endif;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top