SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change syntax from mysqli to mysql

    Hi

    I found this code in internet, and i want to used it , but my database is mysql not mysqli, how can I change my syntax.

    PHP Code:
    <?php    $db = new mysqli('DB_HOST''USERNAME' ,'PASSWORD''DATABASE_NAME');
           if(!
    $db) {     
          echo 
    'Could not connect to the database.'
        } else {   
            if(isset(
    $_POST['queryString'])) {  
               
    $queryString $db->real_escape_string($_POST['queryString']);   
                if(
    strlen($queryString) >0) {         
              
    $query $db->query("SELECT country FROM countries WHERE country LIKE '$queryString%' LIMIT 10");   
                  if(
    $query) {  
                   echo 
    '<ul>';               
          while (
    $result $query ->fetch_object()) {      
                       echo 
    '<li onClick="fill(\''.addslashes($result->country).'\');">'.$result->country.'</li>';              
           }               
      echo 
    '</ul>';                 
      } else {                 
        echo 
    'OOPS we had a problem <IMG class=wp-smiley alt=:( src="http://www.wavesdream.com/wp-includes/images/smilies/icon_sad.gif"> ';        
             }           
      } else {     
                
    // do nothing        
         
    }       
      } else {          
       echo 
    'There should be no direct access to this script!';   
          }    
     } 
    ?>
    Thank you

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    The database is mysql.

    mysql_ and mysqli_ are both PHP database extensions. Another main one is PDO. Comparison of features (at the end of the page).

    You should be able to use mysqli_ without any problems. Did you try?

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used mysql , and no mysqli in my php...

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    I used mysql , and no mysqli in my php...
    With all the security issues that mysql_ has that are fixed in mysqli_ and PDO plus the fact that all supported versions of PHP now support mysqli_ there is no reason for not updating all your database accesses to use the new interface. Even if you don't immediately rewrite all the calls to remove the security holes, changing everything to use either mysqli_ or PDO will at least make it possible to make those security changes as and when you get around to it without having to change all your scripts at once.

    Future versions of PHP will probably drop support for mysql_ completely - it already is optional whether it gets installed or not.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •