Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer is based on the assumption that you're using prepared statements</p> <p>If it's not the case, you should make the necessary adjustments.</p> <p>A. Collect the parameters inside an array</p> <pre><code>$params = array(':name' =&gt; 'foo', ':cat' =&gt; 'bar', ':val' =&gt; 'baz', [...]); </code></pre> <p>B. before calling <code>execute($params)</code>, do as follows, to register in a file the params you're using:</p> <pre><code>file_put_contents('file.log', implode(';', $params) . "\r\n"); //or "\n" on linux, "\r" on mac </code></pre> <p>C. call <code>execute($params)</code></p> <p>D. If the query is successful, GOTO A, otherwise, die.</p> <p>With this simple algorithm you'll have a logfile (named <code>file.log</code>) with all the parameters which have been successfully inserted plus the wrong ones (at the last row).</p> <p><strong>Possible improvement:</strong> </p> <p>This algorithm is not efficient, because you open and close the file multiple times. Follow these instructions instead if you care about efficiency:</p> <p>X. Define <code>$log = array();</code></p> <p>A. Collect the parameters inside an array</p> <pre><code>$params = array(':name' =&gt; 'foo', ':cat' =&gt; 'bar', ':val' =&gt; 'baz', [...]); </code></pre> <p>B. before calling <code>execute($params)</code>, do as follows, to store the params you're using:</p> <pre><code>$log[] = implode(';', $params) . "\r\n"; //or "\n" on linux, "\r" on mac </code></pre> <p>C. call <code>execute($params)</code></p> <p>D. If the query is successful, GOTO A, otherwise, <code>file_put_contents('file.log', implode("\r\n", $log));</code>.</p> <p><strong>Final consideration</strong></p> <p>Combine the above suggestion with the PDO exception that's raised by the error. Its stack is always very useful for debugging purposes.</p> <p>To enable exceptions with pdo, use this command after the connection:</p> <pre><code>$db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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