时间:2021-07-01 10:21:17 帮助过:3人阅读
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) { 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.); } 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); } } |
public function __construct(DB $db) { $this->db = $db; } |
/** *执行当前查询 * * 执行当前查询—用提供的参数代替任何点位符 * . * * @参数: mixed $queryParams,... 查询参数 * @返回:资源A—参考描述执行查询的资源。 */ public function execute($queryParams = ) { //例如: SELECT * FROM table WHERE name=:1S AND type=:2I AND level=:3N $args = func_get_args(); if ($this->stored_procedure) { /*调用compile函数以得到查询*/ $query = call_user_func_array(array($this, compile), $args); } else { /*一个存储过程没被初始化,因此,作为一种标准查询来执行之*/ $query = $queryParams; } $result = $this->db->query($query); if (! $result) { throw new QueryException($this); http://www.bkjia.com/PHPjc/508484.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508484.htmlTechArticle一、 DBQuery对象 现在,我们的DBQuery对象简单地模仿一个存储过程一旦被执行,即返回一个必须进行保存的结果资源;并且如果你想使用该结... 人气教程排行
|