Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>a) Tell PDO that you want it to use exceptions for reporting errors</p> <pre><code>$dbh = new PDO("sqlite::memory:"); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); </code></pre> <p>b) instead of putting the payload paraemters into the sql statement use prepared parametrized statements</p> <pre><code>try { $stmt = $dbh-&gt;prepare( 'SELECT * FROM `item` WHERE combo LIKE ? LIMIT 1' ); $stmt-&gt;execute( array($value) ); foreach( $stmt as $row ) { ... </code></pre> <p>c) If you still don't get any output try code that unconditionally prints something. E.g. a SELECT Count(*) will always return at least one record (if no error occurs).</p> <pre><code>$stmt = $dbh-&gt;prepare( 'SELECT Count(*) as cnt FROM `item` WHERE combo LIKE ?' ); $stmt-&gt;execute( array($value) ); foreach( $stmt as $row ) { echo 'Count: ', $row['cnt'], "\n"; } $stmt = null; </code></pre> <hr> <p>edit: self-contained example</p> <pre><code>&lt;?php ini_set('display_errors', true); error_reporting(E_ALL); echo "start\n"; try { $dbh = new PDO("sqlite::memory:"); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false); setup($dbh); $stmt = $dbh-&gt;prepare('SELECT * FROM item WHERE combo LIKE ? LIMIT 1'); $stmt-&gt;execute( array('comboB') ); foreach( $stmt as $row ) { echo $row['name'], " ", $row['style'], " ", $row['appr'], "\n" ; } } catch(Exception $ex) { var_dump($ex); } echo "done.\n"; function setup($dbh) { $dbh-&gt;exec(' CREATE TABLE item ( combo TEXT, name TEXT, style TEXT, appr TEXT ) '); $stmt = $dbh-&gt;prepare('INSERT INTO item (combo,name,style,appr) VALUES (?,?,?,?)'); $stmt-&gt;execute( array('comboA','nameA','styleA','apprA') ); $stmt-&gt;execute( array('comboB','nameB','styleB','apprB') ); $stmt-&gt;execute( array('comboC','nameC','styleC','apprC') ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload