Search code examples
phpmysqladodbadodb-php

ADOdb and Previewing Prepared Statements (PHP)


According to: https://adodb.org/dokuwiki/doku.php?id=v5:userguide:portable_sql#prepare_execute

$stmt = $db->prepare("SELECT * FROM customers WHERE custid=? AND state=?");
$rs = $db->execute($stmt, array(999,'New York'));

How does one preview the SQL that ADOdb prepares without Executing, first? Namely:

"SELECT * FROM customers WHERE custid=999 AND state='New York'"

Solution

  • This class provides a solution:

    https://github.com/jasny/dbquery-mysql/blob/master/src/Jasny/DB/MySQL/QuerySplitter.php

    $stmt = "SELECT * FROM customers WHERE custid=? AND state=?";
    $params = array(999,'New York');
    
    $split = new QuerySplitter;
    $query = $split->bind($stmt , $params);
    die($query);
    
    //SELECT * FROM customers WHERE custid=99 AND state='New York'