public function find() { $result = array(); $where = 'where 1 = 1 '; foreach ($this->columns as $objCol => $dbCol) { if ($this->{$objCol}) { $where .= " and {$dbCol} = {$this->{$objCol}}"; //only bug: here I " and {$objCol} = {$this->$objCol}"; but with former experience, I know that database handling is the place where bug fills. So I var_dump($sql) and find it. } } $sql = "select * from {$this->table} {$where}"; // var_dump($sql); DataConnection::getConnection(); $rs = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($rs); while ($row) { $o = clone $this; foreach ($o->columns as $objCol => $dbCol) { $o->{$objCol} = $row[$dbCol]; } $result[] = $o; $row = mysql_fetch_array($rs); } return $result; }
function yaoQingjia() { $name = mysql_real_escape_string($_POST['name']); $manager = mysql_real_escape_string($_POST['manager']); $date = mysql_real_escape_string($_POST['date']); $days = mysql_real_escape_string($_POST['days']); $reason = mysql_real_escape_string($_POST['reason']); $sql = "insert into t1_qingjia (qj_id, qj_name, qj_manager, qj_date, qj_days, qj_reason) values ('', '{$name}', '{$manager}', '{$date}', '{$days}', '{$reason}')"; $con = DataConnection::getConnection(); mysql_query($sql, $con) or die(mysql_error()); $id = mysql_insert_id(); return $id; }
public function find() { $result = array(); $where = 'where 1=1 '; foreach ($this->columns as $objCol => $dbCol) { if ($this->{$objCol}) { $where .= " and {$dbCol} = {$this->{$objCol}}"; } } $sql = "select * from {$this->table} {$where}"; DataConnection::getConnection(); $rs = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($rs); while ($row) { $o = clone $this; foreach ($o->columns as $objCol => $dbCol) { $o->{$objCol} = $row[$dbCol]; } $result[] = $o; $row = mysql_fetch_assoc($rs); } // print_r($result); return $result; }