Get Last Executed Query in PHP PDO
来源:互联网 发布:视频大数据应用领域 编辑:程序博客网 时间:2024/06/18 14:46
<?php class MyPDOStatement extends PDOStatement { protected $_debugValues = null; protected function __construct() { // need this empty construct()! } public function execute($values=array()) { $this->_debugValues = $values; try { $t = parent::execute($values); // maybe do some logging here? } catch (PDOException $e) { // maybe do some logging here? throw $e; } return $t; } public function _debugQuery($replaced=true) { $q = $this->queryString; if (!$replaced) { return $q; } return preg_replace_callback('/:([0-9a-z_]+)/i', array($this, '_debugReplace'), $q); } protected function _debugReplace($m) { $v = $this->_debugValues[$m[1]]; if ($v === null) { return "NULL"; } if (!is_numeric($v)) { $v = str_replace("'", "''", $v); } return "'". $v ."'"; } } // have a look at http://www.php.net/manual/en/pdo.constants.php $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_STATEMENT_CLASS => array('MyPDOStatement', array()), ); // create PDO with custom PDOStatement class $pdo = new PDO($dsn, $username, $password, $options); // prepare a query $query = $pdo->prepare("INSERT INTO mytable (column1, column2, column3) VALUES (:col1, :col2, :col3)"); // execute the prepared statement $query->execute(array( 'col1' => "hello world", 'col2' => 47.11, 'col3' => null, )); // output the query and the query with values inserted var_dump( $query->queryString, $query->_debugQuery() );
Get Last Executed Query in PHP PDO
0 0
- Get Last Executed Query in PHP PDO
- PHP PDO exec, query, prepared statement
- mysql php pdo query print_r global echo
- SQL SERVER – Get Last Running Query Based on SPID
- PHP PDO的简单使用(query(),exec(),prepare(),Transaction,行锁)
- PHP+MYSQL中使用PDO的query方法
- Explain plan for last executed statement
- 92 Examine the output of the query that you executed to list the objects in the recycle bin: SQL> SE
- get the last date of a month in oracle
- PHP PDO
- PHP PDO
- PHP PDO
- PHP PDO
- PHP PDO
- PDO PHP
- PHP PDO
- php当中多次使用PDO::query ( string $statement ) 报non-object错误的解决方法
- PDO query和execute区别
- C++ hdoj 2008 数值统计
- 观察者模式II--Java原生实现分析以及一种全新的观察者模式
- JAVA的两种成员变量
- Android开发之数据库备份
- Java 实时论坛 - Sym 1.4.0 发布
- Get Last Executed Query in PHP PDO
- 互联网编程技术
- 御泥坊 部分 网络解析 HttpURLConnection MyAsyncTask
- vc获取当前进程CPU使用率
- 自定义控件之——标题栏
- SEO外链算法独家揭秘
- css 导航栏
- [leetcode] 1. Two Sum
- 简单粗暴!Android Activity泄漏问题解决方案