+ Reply to Thread
Results 1 to 2 of 2

Thread: MySQLi connection

  1. #1
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    MySQLi connection

    What is the difference between a mysql connection and a mysqli connection? I was reading a PHP book that uses mysqli connection and has a way to make sure sql injections do not happen using the mysqli_real_escape_string(). Would I have to change the way I form my queries at all or is it just a different mysql connection type? (assuming $query = "SELECT fields FROM table_name";)

  2. #2
    misson is offline Community Advocate misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,391

    Re: MySQLi connection

    "mysql" is the oldest MySQL driver. It was replaced with mysqli, which supports an OO interface, prepared statements (via mysqli::prepare) and many other improvements. Note that the old mysql driver has its own quoting function (mysql_real_escape_string), but prepared statements are the more modern approach because they leave less room for mistakes and are easier to use, from a security standpoint. Even newer than mysqli is PDO, which has even more features, such as a broader prepared statement interface (with mysqli, you must bind the columns in a result of a prepared statement to variables; with PDO, you can simply fetch them as a row, as with mysql_fetch_row) and the result rows of a query can be iterated over in a foreach loop, since PDOStatement implements the Traversable interface.

    PHP Code:
    $query $db->prepare('SELECT id, name, passwd, last_login FROM users WHERE name=?');
    $query->execute(array('fred'));
    foreach (
    $query as $row) {
        ...

    See "Writing MySQL Scripts with PHP and PDO" for a tutorial on using PDO.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. MySQLi support?
    By streek dime in forum Free Hosting
    Replies: 1
    Last Post: 08-18-2009, 01:57 PM
  2. Mysqli Extension
    By austinw in forum Free Hosting
    Replies: 1
    Last Post: 04-22-2009, 03:01 PM
  3. MySQLi Not working
    By drcore in forum Free Hosting
    Replies: 2
    Last Post: 08-16-2008, 04:23 AM
  4. mysqli not available
    By Eclipse4 in forum Free Hosting
    Replies: 2
    Last Post: 08-13-2008, 01:18 AM
  5. MySQLi extention?
    By lambada in forum Free Hosting
    Replies: 3
    Last Post: 07-04-2007, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers