Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For quickly retrieving a value from something like a <code>SELECT COUNT()</code> query, have a look at <a href="http://www.php.net/manual/pdostatement.fetchcolumn.php" rel="nofollow"><code>PDOStatement::fetchColumn</code></a>, eg</p> <pre><code>$stmt = $pdo-&gt;prepare('SELECT COUNT(1) FROM users WHERE email = :email'); $stmt-&gt;bindParam(':email', $email); $stmt-&gt;execute(); $email_count = $stmt-&gt;fetchColumn(); </code></pre> <p>I'd also like to offer some further advice. You shouldn't be creating a <code>PDO</code> connection in your class constructor. This means that every time you instantiate a class extending <code>Database</code>, you create a new connection. Instead, pass the <code>PDO</code> instance as a dependency, eg</p> <pre><code>abstract class Database { /** * @var PDO */ protected $pdo; public function __construct(PDO $pdo) { $this-&gt;pdo = $pdo; } } </code></pre> <p>The same goes for your <code>User::insert</code> method. Try to pass any required parameters via method arguments. If you ever want to start writing unit tests for your classes, this will be invaluable</p> <pre><code>public function insert($email) { $stmt = $this-&gt;pdo-&gt;prepare('SELECT COUNT(1) FROM users WHERE email = :email'); $stmt-&gt;bindParam(':email', $email); $stmt-&gt;execute(); $email_count = $stmt-&gt;fetchColumn(); // and so on </code></pre> <p>And finally, for PHP only files, omit the closing PHP tag <code>?&gt;</code>. This will save you from accidentally including whitespace at the end of your files that may be sent to the browser.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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