未定义的类常量 'ATTR_ERROR_MODE with PDO [英] Undefined class constant 'ATTR_ERROR_MODE with PDO
本文介绍了未定义的类常量 'ATTR_ERROR_MODE with PDO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 PDO 将数据插入到数据库中:
I wanted to insert data into a database using PDO:
$ServerName='localhost';
$UserName='root';
$DbName='scholar';
$Password='';
try{
$conn=new PDO("mysql::host=$ServerName,dbname=$DbName",$UserName,$Password);
//set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERROR_MODE,PDO::ERRMODE_EXCEPTION);
$sql="INSERT INTO register(id,first,Last,Father,email,gender,phone,category,current,class10,class12,diploma,bachelor,course,poly,btech,leet,time/date)".
"VALUES('','$first','$last','$Father','$email','$gender','$phone','$category',"
."'$current','$class10','$class12','$diploma','$bachelor','$course','$poly','$btech','$leet','$date')";
$conn->exec($sql);
echo'record added successfully';
} catch(PDOException $e){
echo $sql."<br>".$e->getMessage();
$conn=null;
}
但是后来出现了这个错误,我无法修复它:
But then this error occurred, and I can't fix it:
错误:未定义的类常量'ATTR_ERROR_MODE'
error: Undefined class constant 'ATTR_ERROR_MODE'
推荐答案
更正常量
来自
PDO::ATTR_ERROR_MODE
到
PDO::ATTR_ERRMODE
这篇关于未定义的类常量 'ATTR_ERROR_MODE with PDO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文