1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php's Mysql Extension Being Officially Deprecated!

Discussion in 'Databases' started by shuman202, Feb 19, 2013.

  1. #1
    PHP.net has officially announce the extension mysql being deprecated
    if you viste any mysql function description in the php.net
    for examble
    http://www.php.net/manual/en/function.mysql-close.php
    you will get the following notice

    the altenatives are
    MySQLi or PDO_MySQL
    Well I would like to know which of the both (PDO or MySQLi) should I pick to continue my learning progress, taking in mind I have no experience or interest in working on any databases except MySQL, and that I am a newbie.
    i just want to know which one of the is better and more portable and easy to learn
    best regards
    Last edited: Feb 19, 2013
    shuman202, Feb 19, 2013 IP
  2. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #2
    I will probably go with MySQLi
    innozemec, Feb 19, 2013 IP
  3. jestep

    jestep Notable Member Premium Member

    Messages:
    3,486
    Likes Received:
    199
    Best Answers:
    16
    Trophy Points:
    280
    #3
    I prefer PDO to mysqli. If you're just looking for the quickest replacement, mysqli will be a little easier to transition to. PDO is more portable and supports other RDBMS. It also offers quite a bit more features.
    jestep, Feb 20, 2013 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,703
    Likes Received:
    48
    Best Answers:
    9
    Trophy Points:
    100
    #4
    Whenever I come across anybody needing help and I see they're using the old style query type I always urge them to switch to PDO. Well I guess they'd better learn quick! Its not actually that hard to pick up, I found it a little niggly at first but its so much easier and nicer to know you have that added layer of security... for the time being.
    scottlpool2003, Feb 20, 2013 IP
  5. shuman202

    shuman202 Active Member

    Messages:
    527
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    Digital Goods:
    1
    #5
    i think MySQLi is kinda similar to the old mysql
    i just need a quickest replacement
    shuman202, Feb 20, 2013 IP
  6. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,703
    Likes Received:
    48
    Best Answers:
    9
    Trophy Points:
    100
    #6
    I've never learnt MySQLi so I can't really comment other than it is meant to be similar to the old MySQL. PDO is fantastic though and its also not entirely dissimilar either. Here's an example:

    dbconnect.php
    PHP:
    1.  
    2. //Set details
    3. $serverHost = "localhost";
    4. $dbName = "myDB";
    5. $userName = "myUser";
    6. $passWord = "myPass";
    7.  
    8. //Declare new PDO using above credentials
    9. $dbconn = new PDO('mysql:host=$serverHost;dbname=$dbName','$userName','$passWord');
    10.  
    11. //Make sure all is working
    12. try
    13.   {
    14.   $dbPDO = new PDO('mysql:host='.$serverHost.';dbname='.$dbName, $userName, $passWord);
    15.   $dbPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    16.   }
    17.  
    18. //Check for errors
    19. catch  (PDOException $e)
    20.   {
    21.     echo "Error!: " . $e->getMessage() . "
    22. ";
    23.     die();
    24.   }
    insertexample.php
    PHP:
    1.  
    2.  
    3.    // insert info to the db
    4.    $sth = $dbconn->prepare("
    5.   INSERT INTO myTable
    6.   (field1, field2, field3, field4)
    7.   VALUES     (:item1,:item2,:item3,:item4)
    8.   ");
    9.  
    10.        //This is the cool bit, because the items are binded below, PDO AUTOMATICALLY prevents SQL injections making it a heck of a lot safer than the old style
    11.    $params = array(
    12.    item1=> $_POST[item1],
    13.    item2=> $_POST[item2],
    14.    item3=> $_POST[item3],
    15.    item4=> $_POST[item4]
    16.    );
    17.  
    18.        //All set now execute!
    19.    $sth->execute($params);
    20.  

    selectqueryexample.php
    PHP:
    1.  
    2.  
    3. $sth = $dbconn->prepare("
    4. SELECT     item1, item2, item3, item4
    5. FROM         table2
    6. WHERE     (item1 = :item1) AND (item2 = :item2)
    7. ");
    8.  
    9. $params = array("item1" => $_POST[item1], "item2" => $_POST[item2]);
    10. $sth->execute($params);
    11.  
    12. $row = $sth->fetch(PDO::FETCH_ASSOC);
    13.  
    14.  
    15. echo "$row[item1]";
    16.  
    scottlpool2003, Feb 21, 2013 IP
    shuman202 likes this.
  7. shuman202

    shuman202 Active Member

    Messages:
    527
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    Digital Goods:
    1
    #7
    thank you it seems really easy to grasp i'll search for a quickstart tutorial about it
    shuman202, Feb 21, 2013 IP