我一般都把SQL语句给封起来。
例如
[Copy to clipboard]
PHP CODE:
class {...
function query($table, $conditions=array()){
$sql = "select * from " . $table;
if (empty($conditions)==false) {
$sql.= " where ";
foreach ($conditions as $key=>$val) {
$sql .= $key. "=". $val; //处理conditions 我这里只是完成了一个相等条件选择。 还可以继续完善
}
}
$rs = mysql_query($sql);
if ($rs==null) {
return false;
}
while ($t = mysql_fetch_assoc($rs)) {
$this->rs[] = $t;
}
return $this->rs;
}
function exec($sql){
return mysql_query($sql);
}
[
本帖最后由 handy 于 2008-7-7 10:55 编辑 ]