答案 0 :(得分:2)
不要觉得太聪明。
制作一套方法。
query
,返回资源类型。生成SET语句的方法对于插入和更新方法也很有用。有关示例,请参阅this one
示例:
//SELECT helpers:
$username = $db->getOne("SELECT name FROM users WHERE id=?",$id); //getting scalar
$userinfo = $db->getRow("SELECT * FROM users WHERE id=?",$id); //getting row
$newsdata = $db->getAll("SELECT * FROM news LIMIT ?,?",$start,$rows); //getting array
//Select for mass emailing
$res = $db->query("SELECT * FROM notify WHERE topic_id = ?",$topic);
$num = $db->numRows($res);
while ($row = $db->next()){
mail(...);
}
//insert
$res = $db->query("INSERT INTO users SET name = ?",$name);
$id = $db->lastId();
//delete
$res = $db->query("DELETE FROM users WHERE id = ?",$id);
$rows = $db->affectedRows();
但是,我不确定affectedRows()和lastId方法,因为它们将链接标识符作为参数,而不是资源标识符......