您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 辽源分类信息网,免费分类信息发布

PHP的SqlHelp

2024/2/19 22:41:37发布20次查看
pre = $pre; $this->connect($host, $user, $pwd, $db); mysql::$self = $this; } /** * @param string $host * @param string $host * @param string $pwd * @param string $db * @param string $pre * @return db */ public static function init($host='', $user='', $pwd='', $db='', $pre = '') { if(!(mysql::$self instanceof db)){ mysql::$self = new mysql($host, $user, $pwd, $db, $pre); } return mysql::$self; } /** * 创建连接 */ private function connect($host, $user, $pwd, $db, $pre = '') { $this->pre = $pre; if(! $this->link = mysql_connect($host, $user, $pwd)) die( 'connection to mysql server could not be established.'); if(! mysql_select_db($db, $this->link)) die( 'database could not be selected.'); } /** * 执行sql * @param string $sql * @return mysql */ public function query($sql) { $this->times ++; $this->begintime = microtime(); mysql_query('set names '.self::$charset, $this->link); $this->sql = $sql; $this->q = mysql_query($sql, $this->link); $this->alltime[] = array('t' => microtime() - $this->begintime, 's' => $sql); return $this; } /** * 获取单个查询值 * @param string $sql * @return mixed */ public function getone($sql = '') { if(strlen(trim($sql)) > 0){ $this->query($sql); } if($this->check()){ $result = mysql_fetch_array($this->q, mysql_num); mysql_free_result($this->q); return $result[0]; } return false; } /** * 获取一条记录 * @param string $sql * @return array */ public function getrow($sql = '') { if(strlen(trim($sql)) > 0){ $this->query($sql); } if($this->check()){ $result = mysql_fetch_assoc($this->q); mysql_free_result($this->q); return $result; }else{ return array(); } } /** * 获取所有查询 * @param string $sql * @return array */ public function getall($sql = '') { if(strlen(trim($sql)) > 0){ $this->query($sql); } $return = array(); if($this->check()){ while($temp = mysql_fetch_assoc($this->q)) $return[] = $temp; $this->rows = mysql_num_rows($this->q); mysql_free_result($this->q); return $return; }else{ return array(); } } /** * 获取插入id * @return int */ public function insertid($seq=0) { return mysql_insert_id($this->link); } /** * 获取影响行数 * @return int */ public function rownummber() { return $this->rows; } /** * 检查查询是否成功 * @return bool */ public function check() { return $this->q === false ? false : true; } /** * 获得连接 * @return resource */ public function getlink() { return $this->link; } /** * 获得本次连接的查询语句 * @return string */ public function getsql() { return $this->sql; } /** * 获得类名 * @return string */ public function __tostring() { return __class__; } /** * 获得执行时间 * @return float */ public function gettimeinfo() { return $this->alltime; } /** * 获得执行次数 * @return int */ public function gettimes() { return $this->times; } /** * 获得结果行数 * @return int */ public function getresultrows() { $rows = mysql_num_rows($this->q); mysql_free_result($this->q); return $rows; } /** * $id: mysql.php 685 2009-12-03 10:49:04z hh.sun $ * 获得最后执行语句的错误 * @desc getlasterror * @access public * @return string * @version $revision: 685 $ */ public function getlasterror(){ return mysql_error($this->link); } /** * $id: mysql.php 685 2009-12-03 10:49:04z hh.sun $ * mysql_real_escape_string 调用 * @desc escape * @access public * @param string $sql * @return string * * @since 2009-9-25 下午02:06:41 * @version $revision: 685 $ */ public function escape($sql){ return mysql_real_escape_string($sql,$this->link); }}?> 初始化:getone($sql);$line = $db->getrow($sql);$all = $db->getall($sql);//其他文件global $db;$sql = ................................................;$one = $db->getone($sql);$line = $db->getrow($sql);$all = $db->getall($sql);?>
辽源分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录