SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Database connection in MySQLi

    Hi,

    I am revising my old code and replacing mysql with mysqli. Here is what I previously had for a database connection:

    PHP Code:
    $db mysql_connect('host''username''password');
    mysql_select_db('database');
    mysql_set_charset('utf8'$db); 
    and here is what I have now:

    PHP Code:
    $db = new mysqli('host''username''password''database');
    $db->set_charset('utf8'); 
    It seems to be working fine but I just wanted to ask if there are things I should be aware of in converting from mysql to mysqli.

    Thanks.

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,061
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Your connection is fine, where the big difference occur are in the query and fetching of data. I see you are using the OOP syntax for mysqli (good job!), also take time to read about prepare, bind_param, and execute and real_escape_string if you use query
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

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