Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
debug pdo querys
10-20-2013, 06:08 PM (This post was last modified: 10-20-2013 06:08 PM by ionutvmi.)
Post: #1
debug pdo querys
I had to debug some dynamic generated pdo querys today and this function helped big grin

PHP Code:
function pdo_sql_debug($sql,$placeholders){
    foreach(
$placeholders as $k => $v){
        
$sql preg_replace('/:'.$k.'/',"'".$v."'",$sql);
    }
    return 
$sql;


The usage is pretty simple:

PHP Code:
echo pdo_sql_debug("SELECT * FROM table WHERE id = :id", array("id" => 1)); 
Find all posts by this user
Like Post Quote this message in a reply
[-] The following 1 user Likes ionutvmi's post:
thienthanmod (01-01-2015)
10-13-2014, 08:01 PM
Post: #2
RE: debug pdo querys
here's what I think
don't laugh Wrote:>?php
// To debug mysql queries
$fuction='pdo_sql_debug';
$foreach='$k $v';
$id=':id';
$return='sql';
echo ( $function fights with $foreach , $id is brother of $return , $return is the friend of $function , while $id is the friend of $foreach )
<?
Visit this user's website Find all posts by this user
Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)