Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Do not convert mysql_ functions to mysqli_. Period.</h1> <p>There is not a single reason to do that. </p> <p><strong>First, there is no reason to do that just mechanically, changing only function names leaving algorithm the same:</strong></p> <p>Without implementing parameterized queries such a move makes very little sense.<br> If your only concern is "Deprecated" errors - you can just turn them off with </p> <pre><code>error_reporting(E_ALL &amp; ~E_DEPRECATED); </code></pre> <p>and continue happily using old mysql_*<br> Note that you will need that only in 2-3 years, when PHP 5.5 will reach shared hostings.<br> So, there is no need to hurry as well.</p> <p><strong>Second, what you really need is to eliminate all the bare API calls from the code</strong></p> <p>encapsulating them in to some sort of abstraction library. This should be your main concern, not a particular API used in this library, which could be changed in a wink.</p> <p><strong>Finally, the only real reason for switching from <code>mysql_*</code> to <code>mysqli_*</code> is parameterized queries.</strong></p> <h2>And mysqli is totally unusable with them.</h2> <p>With prepared statements PDO is the only choice you have.</p> <p>Let me show you what I mean.<br> Imagine we have an array of checkboxes from HTML form to add into query dynamically.<br> With PDO we can have some relatively sane and quite concise (however still uselessly complex and polluted) code:</p> <pre><code>$in = str_repeat('?,', count($_GET['cat']) - 1) . '?'; $sql = "SELECT * FROM table WHERE category IN ($in)"; $stm = $db-&gt;prepare($sql); $stm-&gt;execute($_GET['cat']); $data = $stm-&gt;fetchAll(); </code></pre> <h2>With mysqli such a trivial case will take you hours of writing and debugging several pages of extremely intricate code.</h2> <p>Just try it and see. </p> <p>However, even PDO require some obscure and useless code to create certain query parts. So, the best way would be to use some more intelligent library, such as <a href="https://github.com/colshrapnel/safemysql" rel="nofollow">safemysql</a>, which will do all the job internally, from binding to fetching, <strong>making all your code into single line</strong>:</p> <pre><code>$data = $db-&gt;getALL("SELECT * FROM table WHERE category IN (?a)", $_GET['cat']); </code></pre>
    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.
    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