PHP userland backwards compatibility layer that emulates PHP 5.5+ core functions.

⌈⌋ ⎇ branch:  upgrade.php


Artifact [9ef43b2fbf]

Artifact 9ef43b2fbfa896c6cb5184ebbb6f74f2493c1e10:

Wiki page [pdo_mysql.php] by mario 2014-03-18 02:34:00.
D 2014-03-18T02:34:00.887
L pdo_mysql.php
N text/x-markdown
U mario
W 1961
<kbd>[pdo_mysql.php](doc/trunk/ext/contrib/pdo_mysql.php)</kbd> provides <b>pdo\_</b> lookalike wrapper functions to more easily replace their <s>mysql_</s> counterparts.

<h3> Tutorial </h3>

See [Q: Why shouldn't I use mysql_* functions in PHP? - A: Easy of Use / Ain't nobody got time for bindValue()](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/20767765#20767765) for a nice summary.

<h3> Rewriting <s>mysql_</s> code </h3>

Transitioning off the dated and cumbersome mysql_ functions can be easy.

  *  Include <kbd>`pdo_mysql.php`</kbd> in your code.
  *  And simply replace all `mysql_` prefixes with `pdo_`

You can then also utilize parameterized queries with little effort:

  <img src=http://i.stack.imgur.com/PeuHl.png>

Which usually leads to more readable code, and implicitly uses PDO behind the scenes.

<h3> Parameterized queries </h3>

Resulting in less fuzz behind the scenes:

  <img src=http://i.stack.imgur.com/M7PXp.png>

`pdo_mysql.php` defaults to real prepared statements.


<h3> Advantages over plain PDO interface </h3>

The instantiation and query functions contain some built-in defaults:

  *  Enable ERRMODE_WARNING per default.
  *  Disable ATTR_EMULATE_PREPARES (some calls temporarily re-enable it).
  *  MYSQL_ATTR_FOUND_ROWS is automatically applied for SELECT queries. Thus pdo_affected_rows() works on updates and retrieval queries.


<h3> Behind the scenes </h3>

When utilizing `pdo_connect()` and `pdo_query()` etc. you get an implicit global variable <kbd>$pdo</kbd>. This can be shared with more contemporary code, utilizing the actual OO PDO interface.

**PDOStatement_Seekable** is a result wrapper, which facilitates scrolling among results. Commonly you should just `foreach` over the result list. But code previously using `mysql_` often seeks forth and back. A small buffer is implemented in PDOStatement_Seekable for this.


Z 0ada0e1a3ede44eeb0adf95711720761