tonyeveland Posted July 29, 2010 Share Posted July 29, 2010 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/209273-php-code-to-access-sql-server-2008-tables/ Share on other sites More sharing options...
Adam Posted July 29, 2010 Share Posted July 29, 2010 Theoretically yeah, just consider the differences in the SQL for future queries. Your function could use some work. Quote Link to comment https://forums.phpfreaks.com/topic/209273-php-code-to-access-sql-server-2008-tables/#findComment-1092794 Share on other sites More sharing options...
tonyeveland Posted July 30, 2010 Author Share Posted July 30, 2010 MrAdam, Thanks for your vague, sarcastic response. You're a great help. Quote Link to comment https://forums.phpfreaks.com/topic/209273-php-code-to-access-sql-server-2008-tables/#findComment-1093117 Share on other sites More sharing options...
Adam Posted July 30, 2010 Share Posted July 30, 2010 I'm sorry? Your question: If I make these changes, would this code work for SQL Server 2008? My answer: Theoretically yeah, just consider the differences in the SQL for future queries. You asked if it would work, and theoretically it would. Those functions were written to be a similar as possible across different database platforms. However as I said take note of the differences within the SQL syntax as that's where you're most likely to run into problems. You want a better response, ask a better question. Oh and yeah, you're function does need some work since you're creating a new connection every time you perform a query. Quote Link to comment https://forums.phpfreaks.com/topic/209273-php-code-to-access-sql-server-2008-tables/#findComment-1093120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.