This article provides a detailed analysis of the implementation of the php version of link_mysql. For more information, see
The code is as follows:
$ Str_ SQL _read = "select count (*) as num from userinfo ";
$ Str_ SQL _del = "delete from userinfo where id = 1 ";
$ Res = link_mysql ("read", $ str_ SQL _read );
$ Res_del = link_mysql ("delete", $ str_ SQL _del );
Echo $ res_del ."
";
While ($ row = mysql_fetch_assoc ($ res ))
{
Echo "". $ row ['num']."
";
}
?>
Function link_mysql ($ opt, $ str_ SQL)
{
$ Con = mysql_connect ("localhost", "root", "root") or die ('not connected: '. mysql_error ());
Mysql_set_charset ("gbk", $ con );
// If you donot know how to use this function, find it defination;
Mysql_select_db ("website", $ con );
Switch ($ opt ){
Case "read ":
$ Res = mysql_query ($ str_ SQL );
Break;
Case "update ":
Case "delete ":
Case "insert ":
$ Res = mysql_query ($ str_ SQL );
Break;
}
Mysql_close ();
Return $ res;
}
?>