prepare($sql)) { return $stmt; } else { throw new Exception($con->error); } } public function getOne($f1) { $con = $this->getConnection(); $stmt = $this->getStatement($con, 'SELECT f1,f2 FROM t1 WHERE f1 = ?'); $stmt->bind_param('i', $f1); $stmt->execute(); $rs = $stmt->get_result(); if($row = $rs->fetch_array()) { $t1 = new T1($row['f1'], $row['f2']); } else { return null; } $stmt->close(); $con->close(); return $t1; } public function getAll() { $res = array(); $con = $this->getConnection(); $stmt = $this->getStatement($con, 'SELECT f1,f2 FROM t1'); $stmt->execute(); $stmt->bind_result($f1, $f2); while($stmt->fetch()) { $res[] = new T1($f1, $f2); } $stmt->close(); $con->close(); return $res; } public function save($t1) { $con = $this->getConnection(); $stmt = $this->getStatement($con, 'INSERT INTO t1 VALUES(?, ?)'); $stmt->bind_param('is', $t1->getF1(), $t1->getF2()); if(!$stmt->execute()) { throw new Exception($stmt->error); } $stmt->close(); $con->close(); } } ?>