php采集接口数据库 php数据采集方法( 三 )


public function getOne($where,$fields = '*') {
$data = https://www.04ip.com/post/$this-select($where,$fields ='*');
if($data) {
return$data[0];
}
return array();
}
//查询多条数据
public function getAll($where,$fields = '*') {
$data = https://www.04ip.com/post/$this-select($where,$fields ='*');
return$data;
}
//结果数量
public function getCount($where = '',$fields = '*') {
$this-condition($where);
$sql = "SELECT count({$fields}) as count FROM `{$this-db}`.`{$this-table}` {$this-condition}";
$data = https://www.04ip.com/post/$this-query($sql);
if($data){
return @mysql_result($data,0);
}
return 0;
}
//执行sql语句(flag为0返回mysql_query查询后的结果,为1返回lastid,其他返回影响行数,默认为2返回影响行数)
public function query($sql, $flag = '0', $type = '') {
if ($this-config['dbDebug']) {
$startime = $this-microtime_float();
}
//查询
if ($type == 'UNBUFFERED'function_exists('mysql_unbuffered_query')) {
$result = @mysql_unbuffered_query($sql, self::$link);
} else {
//exit($sql);
$result = @mysql_query($sql, self::$link);
}
//重试
if (in_array(mysql_errno(self::$link), array(2006,2013))empty($result)$this-config['dbPconnect']==0!defined('RETRY')) {
define('RETRY',true); @mysql_close(self::$link); sleep(2);
$this-connect();
$result = $this-query($sql);
}
if ($result === false) {
$this-errdie($sql);
}
if ($this-config['dbDebug']) {
$endtime = $this-microtime_float();
$this-sql[] = array($sql,$endtime-$startime);
}
//清空操作数据
$this-data = https://www.04ip.com/post/array();
return $flag == '0' ? $result : ($flag == '1' ? $this-getInsertId() : $this-getAffectedRows());
}
//返回结果$onlyone为true返回一条否则返回所有,$type有MYSQL_ASSOC,MYSQL_NUM,MYSQL_BOTH
public function fetch($result, $onlyone = false, $type = MYSQL_ASSOC) {
if($result){
if ($onlyone) {
$row = @mysql_fetch_array($result, $type);
return $row;
}else{
$rowsRs = array();
while($row=@mysql_fetch_array($result, $type)) {
$rowsRs[] = $row;
}
return $rowsRs;
}
}
return array();
}
//可以运行SELECT , SHOW,EXPLAIN 或 DESCRIBE 等返回一个资源标识符的语句得到返回结果数组
public function show($sql, $onlyone = false) {
return $this-fetch($this-query($sql), $onlyone);
}
// 使用call函数处理同类型函数
private function __call($name, $arguments) {
$callArr = array('on', 'where', 'order', 'between', 'group', 'limit');
if (in_array($name, $callArr)) {
$this-data['condition'][$name] = $arguments[0];
}else{
$this-errdie("function error: function {$name} is not in ($this-class) class exist");
}
return $this;
}
//返回最后一次插入ID
public function getInsertId() {
return @mysql_insert_id(self::$link);
}
//返回受影响行数
public function getAffectedRows() {
return @mysql_affected_rows(self::$link);
}
//获取错误信息
private function error() {
return ((self::$link) ? @mysql_error(self::$link) : @mysql_error());
}
//获取错误信息ID
private function errno() {
return ((self::$link) ? @mysql_errno(self::$link) : @mysql_errno());
}
//获取版本信息
function version() {
if(empty($this-version)) {
$this-version = mysql_get_server_info(self::$link);
}
return $this-version;
}
//打印错误信息
private function errdie($sql = '') {
if ($this-config['dbDebug']) {
die('/BRBMySQL ERROR/B/BR
SQL:'.$sql.'/BR

推荐阅读