标签:ast statement from 报错 etc 属性 最新版 实例化 mpp
如果你使用了最新版的XAMPP,那么你几乎不用改变php.ini的设置,就可以使用pdo
but,插了一晚上,程序既不报错也不插入数据,真是气死人,后来发现是实例化pdo对象的时候没有指定字符集。所以一定设定字符集属性,否则极有可能插入数据失败
<?php
$dbtype = ‘mysql‘;
$dbname = ‘olddream‘;
$user = "root";
$pwd = "wenwajiao";
$ip=‘127.0.0.1‘;
$fuckingcharset = ‘utf8‘;
$dsn = "$dbtype:host=$ip;dbname=$dbname;charset=$fuckingcharset";
$pdo = new PDO($dsn,$user,$pwd);
$rows = $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<count($ret);$i++)
{
$sql = "insert into rbac_user (userid,username,mypass) values (?,?,?)";
$statement=$pdo->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;
<?php
$dbtype=‘mysql‘;
$db = ‘olddream‘;
$ip=‘127.0.0.1‘;
$user=‘root‘;
$pwd = ‘wenwajiao‘;
$charset = ‘utf8‘;
$dsn = "$dbtype:host=$ip;dbname=$db;charset=$charset";
$pdo=new PDO($dsn,$user,$pwd);
$sql = "insert into rbac_user (userid,username,mypass) values (?,?,?)";
$statement=$pdo->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();
?>
标签:ast statement from 报错 etc 属性 最新版 实例化 mpp
原文地址:https://www.cnblogs.com/saintdingspage/p/10807211.html