| require 'mysql_db.php'; require_once 'query.php'; $db = new MySqlDb; $db->connect('host', 'username', 'pass'); $db->query('use content_management_system'); $query = new DBQuery($db); $query->prepare('SELECT fname,sname FROM users WHERE username=:1S AND pword=:2S AND expire_time<:3I'); try { if($query->execute("visualad", "apron", time()))->num_rows() == 1) { hot007.com echo('Correct Credentials'); } else { echo('Incorrect Credentials / Session Expired'); } } catch (QueryException $e) { echo('Error executing query: ' . $e); } |
| class DBQuery { ..... public function fetch_array() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_array($this->result); } public function fetch_row() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_row($this->result); } public function fetch_assoc() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); 文章来源于www.jc567.cn } return $this->db->fetch_assoc($this->result); } public function fetch_object() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->fetch_object($this->result); } public function num_rows() { if (! is_resource($this->result)) { throw new Exception('Query not executed.'); } return $this->db->num_rows($this->result); } } |