942,788 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 248
  • PHP RSS
Jul 29th, 2010
0

PHP Code to access SQL SERVER 2008 tables

Expand Post »
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;
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tonyeveland is offline Offline
4 posts
since Jul 2009
Jul 30th, 2010
0
Re: PHP Code to access SQL SERVER 2008 tables
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
Jul 30th, 2010
0
Re: PHP Code to access SQL SERVER 2008 tables

Thanks, Kararey. I'll check it out
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tonyeveland is offline Offline
4 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: setting the value in my
Next Thread in PHP Forum Timeline: How to tell if a member is online or offline?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC