Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts

    Best way to communicate with a database?

    with mysql_query($query) being out-dated

    whats the best way to query a database?

    Mysqli, PDO etc?

    and what are the advantages of each?

    this is my current db.php:

    PHP Code:

    function Q($query) {
        
    $Username 'root';
        
    $Password '***';
        
    $Database '***';
        
    $Host 'localhost';
        global 
    $queries$queries_time$queries_count;
        
    $queries_count++;
        
    mysql_connect($Host$Username$Password) or die ( 'Unable to connect to the server.<br>' );
        
    mysql_select_db($Database) or die ( 'Unable to select the database.<br>' );
        
    $queries .= 'Line <b>'__LINE__ '</b> of file <b>' .__FILE__ '</b> requested <b>' $query '</b>';
        
    $time_overall round(microtime(),4);
        if (!
    $result mysql_query($query))    {
            echo 
    '<pre>Error on line <b>'__LINE__ '</b> of file <b>' __FILE__ '</b> requesting <b>' $query '</b></pre><br>';
            
    $queries .= ' <b>ERROR OCCURED</b><br>';
        } else {
            
    $queries .= '<br>';
        }
        
    $time2_overall round(microtime(), 4);
        
    $gen_overall $time2_overall $time_overall;
        
    $queries_time substr($queries_time $gen_overall,0,6) ;
        
    mysql_close() or die ( 'Unable to disconnect from the server.<br>' );
        return 
    $result;

    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,316
    Thanks
    23
    Thanked 613 Times in 612 Posts
    I was hoping someone would gives some answers to this, because I'm on the fence with this also.
    I went with MySqli because it's easy to convert from MySql. I have also read that PDO in php is buggy.

    But PDO is the standard(or so I have been told) and I shall go to it as soon as I hear that it is not buggy. Also, PDO is object orientated so getting things from the db and into an object is easier. CLARIFY: I don't use objects to often so this statement is from hearsay, but will start when I learn PDO.

    That's my 2cents. Hope others will post here.
    Free bump.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,996
    Thanks
    79
    Thanked 4,433 Times in 4,398 Posts
    Use ASP.NET? <grin/>

    Sorry, I just couldn't help it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •