Page 1 of 1

help creating my connection object

Posted: Tue Apr 12, 2011 11:22 am
by happyneil
I am currently developing a drupal 6 website on a WAMP server. Windows 7, Apache 2.2.11, MySQL 5.1.36 and PHP 5.3.0. I need to be able to query some data from a Microsoft SQL Server 2008 database.

I currently have this script below, but I have been told that I need to create my own connect string because mssql_connect() is not supported by PHP 5.3.0.

Code: Select all

<?php
$myServer = "COMPNAME\SQLEXPRESS";
$myUser = "dbadmin";
$myPass = "dbadmin";
$myDB = "database123"; 

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 

if (!$dbhandle) {
    die('Something went wrong while connecting to MSSQL');
}  
  
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB"); 


//close the connection
mssql_close($dbhandle);
?>
KEEP ON GETTING THIS ERROR:
Fatal error: Call to undefined function mssql_connect()


I have been advised that I need to create my own connection object and connect to MSSQL. So I need to create my own 'mssql_connect' object. Is there anybody out there that can give me assistance on how I would go about doing this... ANY HELP WOULD BE APPRECIATED!!

Cheers!!

Re: help creating my connection object

Posted: Tue Apr 19, 2011 9:08 am
by zyntrax
You get that error because you don't have mssql extension for php

Here this is what i use:
http://www.microsoft.com/downloads/en/d ... 52214caad9
and the connection string:

Code: Select all

$connectionInfo = array('Database'=>'database123', 'UID'=>'dbadmin', 'PWD'=>'dbadmin'); 
$conn = sqlsrv_connect( "COMPNAME\SQLEXPRESS", $connectionInfo);
if( $conn )
{
     echo "Connection established.\n";
}
else
{
     echo "Connection could not be established.\n";
     die( print_r( sqlsrv_errors(), true));
}