NYCPHP Meetup

NYPHP.org

[nycphp-talk] Connect to MSSQL Database with PHP and ADODB

Randal Rust randalrust at gmail.com
Wed Dec 7 19:30:33 EST 2005


I have inherited a .NET app that I am converting over to PHP/MySQL.
The first big hurdle is to convert the database.

I have setup SQL Server Express 2005 and done a restore of the DB, so
I can at least see the structure and the data.

I am trying to use ADODB to connect to the database, but with no luck.
I set SQL server up so that it uses Windows Authentication when I
login (no username/password) required.  The server name is
VAIOLAPTOP\SQLEXPRESS.

I have a database class that I use to create the connection (see
below). I'm sure that whatever it is I don't have correct is simple,
but I cannot find anything via Google that is providing any answers,
so any help would be greatly appreciated. TIA.

<?php

class DB {

	var $conn;
	
	//constructor
	function DB (){
		//include 'adodb/adodb.inc.php';
		$this->conn =& ADONewConnection('mssql');
		if($ip=$_SERVER['REMOTE_ADDR']=='127.0.0.1'){
			$conn=$this->conn->PConnect('localhost','','','ossrc');
			}
			else {
							$conn=$this->conn->PConnect('localhost','','','rsquared_ossrc');
				}
		
		return $conn;
		}
	
	}

?>

--
Randal Rust
www.r2communications.com



More information about the talk mailing list