Blogger Information
Blog 38
fans 0
comment 1
visits 36378
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
关于PDO判断错误信息并输出
夜澜风的博客
Original
1276 people have browsed it

实例

try{

}catch(PDOException //异常类){

}这是一个固定的格式

运行实例 »

点击 "运行实例" 按钮查看在线实例


try{     

  $p=new PDO($dsn,$dbname,$dbpw);

  }catch(PDOException $e){       //将PDOException错误信息赋值给 $e 然后将 -> (符号,是类的访问,可以请求类里面的方法,固定的符号,不允许改变)

  print_r($e->getMessage());   //这里不能直接打印$e 需要将类里面错误方法信息赋值给getMessage()

  exit;

  }

query -执行 SQL 语句,以 PDOStatement 对象形式返回结果集 ::query 也是一个类 可以通过execute 预处理输出 

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post