PDO中捕获SQL语句中的错误——告警模式
来源:互联网 发布:寻侠武功生肖突破数据 编辑:程序博客网 时间:2024/06/03 21:22
一 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>使用警告模式——PDO::ERRMODE_WARNING捕获SQL中的错误</title><style type="text/css"><!--body,td,th {font-size: 12px;}--></style></head><body><table id="__01" width="464" height="336" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="3"><img src="images/mysql_01.gif" width="464" height="139" alt=""></td></tr><tr><td><img src="images/mysql_02.gif" width="78" height="136" alt=""></td><td width="312" height="136" valign="top"><table width="310" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="30" align="center"><strong>ID</strong></td> <td align="center"><strong>PDO</strong></td> <td align="center"><strong>数据库</strong></td> <td align="center"><strong>时间</strong></td> </tr> <?php$dbms='mysql'; //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数$host='localhost'; //数据库主机名$dbName='db_database15'; //使用的数据库$user='root'; //数据库连接用户名$pass='root'; //对应的密码$dsn="$dbms:host=$host;dbname=$dbName";try { $pdo = new PDO($dsn, $user, $pass); //初始化一个PDO对象,就是创建了数据库连接对象$pdo//$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);//设置为警告模式$query="select * from tb_pdo_mysqls";//定义SQL语句$result=$pdo->prepare($query);//准备查询语句$result->execute();//执行查询语句,并返回结果集while($res=$result->fetch(PDO::FETCH_ASSOC)){//while循环输出查询结果集,并且设置结果集的为关联索引?> <tr> <td height="22" align="center" valign="middle"><?php echo $res['id'];?></td> <td align="center" valign="middle"><?php echo $res['pdo_type'];?></td> <td align="center" valign="middle"><?php echo $res['database_name'];?></td> <td align="center" valign="middle"><?php echo $res['dates'];?></td> </tr><?php } } catch (PDOException $e) { die ("Error!: " . $e->getMessage() . "<br/>");} ?> </table></td><td><img src="images/mysql_04.jpg" width="74" height="136" alt=""></td></tr><tr><td colspan="3"><img src="images/mysql_05.gif" width="464" height="61" alt=""></td></tr></table></body></html>
二 运行结果
阅读全文
0 0
- PDO中捕获SQL语句中的错误——告警模式
- PDO中捕获SQL语句中的错误——静默模式
- PDO中捕获SQL语句中的错误——异常模式
- PDO中捕获SQL语句中的错误
- PDO中捕获SQL语句中的错误
- PDO捕获SQL语句、PDO中错误处理与PDO事务处理
- PDO中执行SQL语句
- PDO中执行SQL语句
- trigger中捕获发生错误的sql语句
- pdo中预处理类执行SQL语句
- PDO执行SQL语句
- Oracle中捕获问题SQL语句
- PHP+MYSQL中使用PDO中执行SQL语句
- PDO中错误处理
- 小随笔——数据库级联、PDO捕获数据库异常
- 捕获排序SQL语句
- 三层模式中,多条件查询中的sql语句拼接
- PDO的错误处理模式
- HRBUST2343 巴啦啦能量(字符串,技巧)
- PDO中捕获SQL语句中的错误——静默模式
- Django配置
- leetcode题解-8. String to Integer (atoi) && 468. Validate IP Address
- 在服务器上配置pytorch
- PDO中捕获SQL语句中的错误——告警模式
- 微信蓝牙硬件设备接入(2)
- 第九周项目3---利用二叉树遍历思想解决问题
- eclipse 配置svn
- 一脸懵逼学习Storm的搭建--(一个开源的分布式实时计算系统)
- PDO中捕获SQL语句中的错误——异常模式
- PDO中的错误处理errorCode方法
- PDO中的错误处理errorInfo方法
- HTML5 进阶系列:拖放 API 实现拖放排序