Note that there are some explanatory texts on larger screens.

plurals
  1. POPDO empy result from SELECT when using AND
    primarykey
    data
    text
    <p>I've come upon a rather interesting thing, which I can't seem to figure out myself. Everytime when executing a SQL statement which contains a '... AND ...' the result is empty.</p> <p>Example:</p> <pre><code>echo('I have a user: ' . $email . $wachtwoord . '&lt;br&gt;'); $dbh = new PDO($dsn, $user, $password); $sql = 'SELECT * FROM user WHERE email = :email AND wachtwoord= :wachtwoord'; $stmt = $dbh-&gt;prepare($sql); $stmt-&gt;bindParam(:email,$email,PDO::PARAM_STR); $stmt-&gt;bindParam(:wachtwoord,$wachtwoord,PDO::PARAM_STR); $stmt-&gt;execute(); while($row = $stmt-&gt;fetchObject()) { echo($row-&gt;email . ',' . $row-&gt;wachtwoord); $user[] = array( 'email' =&gt; $row-&gt;email, 'wachtwoord' =&gt; $row-&gt;wachtwoord ); } </code></pre> <p>The first echo displays the correct values, however the line with </p> <pre><code>echo($row-&gt;email . ',' . $row-&gt;wachtwoord); </code></pre> <p>is never reached. A few things I want to add: 1) I am connected to the database since other queries work, only the ones where I add an 'AND' after my 'WHERE's fail. 2) Working with the <em>while</em> works perfectly with queries that do not contain '... AND ...' 3) Error reporting is on, PDO gives no exceptions on my query (or anything else) 4) Executing the query directly on the database <em>does</em> give what I want:</p> <pre><code>SELECT * FROM user WHERE email = 'jurgen@email.com' AND wachtwoord = 'jurgen' </code></pre> <p>I can stare at it all day long again (which I already did once, but I managed to work around the 'AND'), but maybe one of you can give me a helping hand.</p> <p>Thank you in advance.</p> <p>Jurgen</p>
    singulars
    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.
 

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