/** * Prepares a statement and executes the statement using the given query and parameters * @param string $sql A string of the sql query * @param array $params An array of the parameter * @todo Add proper exception handling * @since version 2.0 * @static */ public static function execute($sql, $params = array()) { /* clear stmt */ self::$stmt = ""; try { self::$stmt = self::DBi()->prepare($sql); return self::$stmt->execute($params) ? true : false; } catch (PDOException $e) { return self::pdoException($e); } }
/** * ****************************************** * 获取记录总数 * 返回:记录数 * 类型:数字 * 参数:select count(*) from table * ******************************************* */ public function getRows($sql = '') { if ($sql) { /* if (self::$debug) { echo $sql . '<br />'; } */ /* self::$stmt = self::$DB->query ( $sql ); //self::getErrInfo (); //self::$querycount ++; $result = self::$stmt->fetchColumn (); self::$stmt = null; */ self::$stmt = self::$DB->prepare($sql); self::$stmt->execute(); $result = self::$stmt->rowCount(); } elseif (self::$stmt) { $result = self::$stmt->rowCount(); } else { $result = 0; } return $result; }
public static function setDatabase() { self::$stmt = self::getInstance()->query('use ' . self::$DB_DATABASE); self::$stmt->closeCursor(); }