Executing the Select statement using MSSQL (works with MySQL)

I connected to MSSQL, but I don’t know how to make a select statement and print it. I did this using MySQL, but could not convert it to MSSQL. Can someone help me find equvalent for mysql_query , mysql_real_escape_string , mysql_num_rows , mysql_fetch_array or sample code that helps.

 // Connecting to MSSQL - Working $name = $_POST['myname']; $x=mysql_query("SELECT * FROM MyTable WHERE Name='".mysql_real_escape_string($name)."'"); $num_rows = mysql_num_rows($x); while($norows = mysql_fetch_array($x)) { // PRINT ROW } 
+4
source share
2 answers

The following alternative functions exist in MSSQL:

 mysql_query ---> mssql_query mysql_num_rows ---> mssql_num_rows mysql_fetch_array ---> mssql_fetch_array 

Take a look at the official documentation here for more information ...

The only missing function is the escape line ( mysql_real_escape_string ), for this purpose you can define yourself as a function:

 function mssql_escape($str) { if(get_magic_quotes_gpc()) { $str= stripslashes($str); } return str_replace("'", "''", $str); } 
+3
source

All Articles