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

MySQL PDO连接与操作

2024/5/11 14:19:04发布32次查看
//实例化pdo类 连接数据库  参数是 mysql:host=localhost;dbname=lamp 用户名  密码$pdo = new pdo('mysql:host=localhost;dbname=lamp', 'root', '');
//查询语句
$sql = select * from lamp_login;$stmt = $pdo->query($sql);
//增 删 改
$pdo->exec($sql);
pdo::fetch_obj相当于mysql_fetch_object
object(stdclass)[3] public 'id' =>string'1'(length=1) public 'username' =>string'user1'(length=5) public 'password' =>string'123'(length=3)
pdo::fetch_both相当于mysql_fetch_array
array(size=6) 'id' =>string'2'(length=1) 0 =>string'2'(length=1) 'username' =>string'user2'(length=5) 1 =>string'user2'(length=5) 'password' =>string'234'(length=3) 2 =>string'234'(length=3)
pdo::fetch_num相当于mysql_fetch_row
array(size=3) 0 =>string'3'(length=1) 1 =>string'user3'(length=5) 2 =>string'345'(length=3)
pdo::fetch_assoc相当于mysql_fetch_assoc
array(size=3) 'id' =>string'4'(length=1) 'username' =>string'zhouyao'(length=7) 'password' =>string'123456'(length=6)
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了mysql pdo连接与操作,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

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