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 Prominent Member Premium Member

    Messages:
    3,529
    Likes Received:
    201
    Best Answers:
    17
    Trophy Points:
    330
    #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,707
    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:
    619
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    95
    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,707
    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
    
    //Set details
    $serverHost = "localhost";
    $dbName = "myDB";
    $userName = "myUser";
    $passWord = "myPass";
     
    //Declare new PDO using above credentials
    $dbconn = new PDO('mysql:host=$serverHost;dbname=$dbName','$userName','$passWord');
     
    //Make sure all is working
    try
      {
      $dbPDO = new PDO('mysql:host='.$serverHost.';dbname='.$dbName, $userName, $passWord);
      $dbPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      }
     
    //Check for errors
    catch  (PDOException $e)
      {
        echo "Error!: " . $e->getMessage() . "
    ";
        die();
      }
    PHP:
    insertexample.php
    
     
       // insert info to the db
       $sth = $dbconn->prepare("
       INSERT INTO myTable
       (field1, field2, field3, field4)
       VALUES     (:item1,:item2,:item3,:item4)
       ");
     
           //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
       $params = array(
       item1=> $_POST[item1], 
       item2=> $_POST[item2], 
       item3=> $_POST[item3], 
       item4=> $_POST[item4]
       );
     
           //All set now execute!
       $sth->execute($params);
    
    PHP:

    selectqueryexample.php
    
     
    $sth = $dbconn->prepare("
    SELECT     item1, item2, item3, item4
    FROM         table2 
    WHERE     (item1 = :item1) AND (item2 = :item2)
    ");
     
    $params = array("item1" => $_POST[item1], "item2" => $_POST[item2]);
    $sth->execute($params);
     
    $row = $sth->fetch(PDO::FETCH_ASSOC);
     
     
    echo "$row[item1]";
    
    PHP:
     
    scottlpool2003, Feb 21, 2013 IP
    shuman202 likes this.
  7. shuman202

    shuman202 Active Member

    Messages:
    619
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    95
    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