try{
$dsn="host=localhost;mysql:dbname=jiahua";//告诉主机和要操作的数据库类型是mysql 和数据库名$user='root';//用户名$psw="123456";//密码//获取new PDO(host=localhost;mysql:dbname=jiahua,'root',123456);$pdo= new PDO($dsn, $user, $psw);//其实就相当于mysql_connect($host,$user,$pw)$pdo->setAttribute(PDO::ATTR_ERRMOTE,PDO::ERRMOTE_EXCEPTION);//设置错误模式var_dump($pdo);die();//执行插入语句$sql="insert into login (username,password) values(?,?)";$stmt=$pdo->prepare($sql);//准备语句 返回一个预处理对象;var_dump($stmt);
}catch (Pdoexception $e) {
echo"错误信息". $e->getMessage()."
";//获取错误信息echo"错误文件".$e->getFile()."
";//获取异常的文件echo "错误行".$e->getLine()."
";//获取错误行echo "错误号".$e->getCode();//获取错误号
}
This is a hint.
Error message could not find driver
Error file G:\wamp\www\bst\wuxianji.php
Error Line 6
Error number 0
The Wamp configuration item is already open.
Reply content:
try{
$dsn="host=localhost;mysql:dbname=jiahua";//告诉主机和要操作的数据库类型是mysql 和数据库名$user='root';//用户名$psw="123456";//密码//获取new PDO(host=localhost;mysql:dbname=jiahua,'root',123456);$pdo= new PDO($dsn, $user, $psw);//其实就相当于mysql_connect($host,$user,$pw)$pdo->setAttribute(PDO::ATTR_ERRMOTE,PDO::ERRMOTE_EXCEPTION);//设置错误模式var_dump($pdo);die();//执行插入语句$sql="insert into login (username,password) values(?,?)";$stmt=$pdo->prepare($sql);//准备语句 返回一个预处理对象;var_dump($stmt);
}catch (Pdoexception $e) {
echo"错误信息". $e->getMessage()."
";//获取错误信息echo"错误文件".$e->getFile()."
";//获取异常的文件echo "错误行".$e->getLine()."
";//获取错误行echo "错误号".$e->getCode();//获取错误号
}
This is a hint.
Error message could not find driver
Error file G:\wamp\www\bst\wuxianji.php
Error Line 6
Error number 0
The Wamp configuration item is already open.
Open, you have to have PDO expansion.
To download a copy of the PDO DLL file