这篇文章给大家分享的是有关php中有哪些pdo类方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
浚县网站建设公司创新互联建站,浚县网站设计制作,有大型网站制作公司丰富经验。已为浚县成百上千家提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的浚县做网站的公司定做!
php pdo类方法有:1、exec方法;2、query方法;3、lastInsertId方法;4、setAttribute方法等等。
pdo类常用方法:
exec()
query()
lastInsertId()
exec('set names utf8');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_BOTH);
$sql="insert into user(username,age) values('user123','55')";
if($pdo->exec($sql)){
$lastid=$pdo->lastInsertId();
echo "ID为{$lastid}的数据插入成功!";
}
?>• setAttribute()
设置获取模式属性
exec('set names utf8');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
$sql="select * from user";
$smt=$pdo->query($sql);
$rows=$smt->fetchAll();
echo '';
print_r($rows);
echo '
';
?>
***
获取索引数组
exec('set names utf8');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_NUM);
$sql="select * from user";
$smt=$pdo->query($sql);
$rows=$smt->fetchAll();
echo '';
print_r($rows);
echo '
';
?>.jpg)
获取混合数组
exec('set names utf8');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_BOTH);
$sql="select * from user";
$smt=$pdo->query($sql);
$rows=$smt->fetchAll();
echo '';
print_r($rows);
echo '
';
?>.jpg)
感谢各位的阅读!关于php中有哪些pdo类方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!