博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用pdo,使用pdo无法插入数据怎么办
阅读量:4650 次
发布时间:2019-06-09

本文共 878 字,大约阅读时间需要 2 分钟。

如果你使用了最新版的XAMPP,那么你几乎不用改变php.ini的设置,就可以使用pdo

but,插了一晚上,程序既不报错也不插入数据,真是气死人,后来发现是实例化pdo对象的时候没有指定字符集。所以一定设定字符集属性,否则极有可能插入数据失败

  • 一个插入多条数据的例子(用到了事务)
prepare("select userid,username from userlist");$rows->execute();$pdo->beginTransaction();$ret = $rows->fetchAll();//update rbac_user set mypass = ? where userid = ?for($i=0;$i
prepare($sql); $statement->bindValue(1,$ret[$i]['userid']); $statement->bindValue(2,$ret[$i]['username']); $statement->bindValue(3,md5($ret[$i]['userid'])); $statement->execute();}$pdo->commit();$pdo=null;
  •  插入一条数据
prepare($sql);$userid = 'masterzhang';$username = '张教练';$pwd = md5('masterzhang');$statement->bindValue(1,$userid,PDO::PARAM_STR);$statement->bindvalue(2,$username,PDO::PARAM_STR);$statement->bindvalue(3,$pwd,PDO::PARAM_STR);$statement->execute();?>

 

转载于:https://www.cnblogs.com/saintdingspage/p/10807211.html

你可能感兴趣的文章