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


ERRNO:'.$this-errno().'/BR
ERROR:'.$this-error().'/BR');
}
die('DB ERROR?。。?);
}
//获取时间微妙数
private function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
//析构函数
public function __destruct() {
echo 'hr';
$this-config['dbDebug']print_r($this-sql);
//unset($this-result);
//unset($this-condition);
//unset($this-data);
}
}
class user extends Model {
//public $db = 'qsf_mvc';
//public $table = 'user';
public $primaryKey = 'uid';
}
$userObj = new user();
//---------------------------------------插入数据方法一-----------------------------------------
//模拟ActiveRecord模式 插入数据
$userObj-username = 'hoho';
$userObj-passwd = '1478522';
$userObj-email = 'qsf.z11@163.com';
$userObj-sex= 1;
$userObj-desc= '清洁工';
【php采集接口数据库 php数据采集方法】$insetId = $userObj-insert();
if ($insetId0) {
echo "插入ID为:{$insetId}BR";
}
//---------------------------------------插入数据方法二-----------------------------------------
//直接数组做参数插入数据
$userArr= array(
'username' = 'hoho',
'passwd' = '1478522',
'email' = 'qsf.z2121ia@163.com',
'sex' = '1',
'desc' = '厨师',
);
$insetId = $userObj-insert($userArr);
if ($insetId0) {
echo "插入ID为:{$insetId}BR";
}
//---------------------------------------更新数据方法一----------------------------------------
$userObj-username = 'h111oho';
$userObj-passwd = '1478511122';
$userObj-email = 'qsf111ia@163.com';
$userObj-sex= 1;
$userObj-desc= '清洁工';
$affectedRows1 = $userObj-update(89);
if ($affectedRows10) {
echo "影响行数为:{$affectedRows1}BR";
}
//---------------------------------------更新数据方法二----------------------------------------
//更新记录(传递参数的方式和insert操作一样)
$userArr= array(
'username' = 'hohoho',
'passwd' = '1474rr4448522',
'email' = 'qsf.rrza@165.com',
'sex' = '0',
'desc' = '厨师qq',
);
$affectedRows = $userObj-update($userArr, $insetId);
if ($affectedRows0) {
echo "影响行数为:{$affectedRows}BR";
}
//----------------------------------------查询数据----------------------------------------------
$userRs0 = $userObj-select(8);//单个主键值
//print_r($userRs0);
$userRs1 = $userObj-select(array(1,5,8));//多个主键值的数组
//print_r($userRs1);
$userRs2 = $userObj-select('select count(*) as count fromuser where uid20');//直接完整sql语句
//print_r($userRs2);
$userRs3 = $userObj-select("`uid`0");//where条件
//print_r($userRs3);
$userRs4 = $userObj-getOne("`uid`0"); //获取单条记录
//print_r($userRs4);
$usersRs5 = $userObj-getAll("`uid`0"); ////获取所有记录
//print_r($usersRs5);
$usersRs6 = $userObj-limit('0,10')-where('uid100')-order('uid DESC')-group('username')-select();
//print_r($usersRs6);
//----------------------------------------删除数据-----------------------------------------------
//删除操作传递参数的方式和select操作一样
$userObj-delete(60);//单个主键值
$userObj-delete(array(1,5,8));//多个主键值的数组
$userObj-delete('deletefromuser where uid100');//直接完整sql语句
$userObj-delete("`uid`100");//where条件
$userObj-limit('5')-where('uid80')-delete();
//----------------------------------------特殊查询-----------------------------------------------
$userShowRs = $userObj-show('show create table user', true);//获取特殊查询的结果,第二个参数代表返回一条结果还是所有的结果

推荐阅读