Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually, a simple, sweet and short: Yes, not necessary any longer.</p> <p>Let's review the code not that we have lost something:</p> <ul> <li><p><code>__construct</code> - The constructor merely contained all the configuration. PDO has a much easier concept here, a connection string containing the most information:</p> <blockquote> <pre><code> mysql:host=127.0.0.1;dbname=people;charset=UTF-8 </code></pre> </blockquote> <p>Also PDO provides the constructor for use ready-made, so double not necessary.</p></li> <li><p><code>connect</code> - The connection function is not necessary any longer as well. This is done by instantiating PDO already. You can look for exceptions, the PHP manual has an example <a href="http://php.net/pdo.construct#example-966" rel="nofollow noreferrer">on it's constructor page</a>.</p></li> <li><p><code>selectDb</code> - This complicated function is not needed any longer as well. Wow, the third function we can just drop because of the PDO connection string. Much power with so less characters. Cheers!</p></li> <li><p><code>__destruct</code> - The destructor. Let's be fair: MySQL did not need this as well. However with PDO we get it for free - without writing a single line of code.</p></li> </ul> <p>Looks good! You managed to migrate from that obscure database class to PDO by removing outdated code! Congratulations:</p> <pre><code>$db = new PDO('mysql:host=127.0.0.1;dbname=people;charset=UTF-8', 'root', 'pass'); </code></pre> <p>If you now think, what about if I want to have database class on my own? Well you can do that, because you can extend from PDO (yes that works!):</p> <pre><code>class DB extends PDO { ... my super-new-shiny-code } </code></pre> <p>Why you might want to do that? No idea, but maybe it's more fluent for your code. If you're looking for a better code-example, I have one at <a href="https://stackoverflow.com/a/10622205/367456">PHP/MySQL Table with Hyperlinks</a>.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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