在PHP4下,若是要調用數據庫進行查詢刪除等操做,須要輸入N行命令。下面是一個簡化的類,能夠用於調用。
class db_class{
function sql($query)
{
global $db_user,$db_password,$db,$db_server;
$db_conn = mysql_connect($db_server,$db_user,$db_password);
mysql_select_db($db_db);
$result = mysql_query($query,$db_conn);if (!$result)
{
$result = 0;
}
if (mysql_num_rows($result)<1)
{
$result = 1;
}
return $result;
}
}
這個類會被我逐漸完善,用法:
$db = new db_class;$result = $db->sql("select * from admin");