954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Code to access SQL SERVER 2008 tables

To access MySql tables from PHP, I use the PHP code and the function below.

If I make these changes, would this code work for SQL Server 2008?

mysql_fetch_array to mssql_fetch_array
mysql_connect to mssql_connect
mysql_select_db to mssql_select_db
mysql_query to mssql_query

PHP code
--------------------------------------------------------------------------------
$sql = "SELECT mast_id FROM district_mast WHERE mast_district = '".$dist_num."'";
$result = func_table_access($sql);
$rows = mysql_fetch_array($result);

Function
--------------------------------------------------------------------------------
FUNCTION func_table_access($sql) {
$db = "aplustutoru";
$host = "localhost";
$user = "root";
$pass = "";

IF (!($conn=mysql_connect($host, $user, $pass))) {
PRINTF("error connecting to DB by user = $user and pwd=$pass");
EXIT;
}

$db3 = MYSQL_SELECT_DB($db,$conn) or die("Unable to connect to local database");
IF ($sql <> "justopendb") {
$result = MYSQL_QUERY($sql) OR DIE ("Can not run query because ". MYSQL_ERROR());
RETURN $result;
}
}

tonyeveland
Newbie Poster
4 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 
katarey
Junior Poster
167 posts since Jul 2005
Reputation Points: 39
Solved Threads: 23
 

see this it may help you

http://msdn.microsoft.com/en-us/library/cc793139%28SQL.90%29.aspx


Thanks, Kararey. I'll check it out

tonyeveland
Newbie Poster
4 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You