Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How change syntax from mysqli to mysql?

mysqli mysql syntax

  • Please log in to reply
2 replies to this topic

#1 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 27 October 2011 - 12:46 AM

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 $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
  • 0

#2 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts
  • Location:Quebec City
  • Programming Language:Java, C++, C#, PHP, JavaScript, Visual Basic .NET, Transact-SQL, ActionScript

Posted 27 October 2011 - 04:11 AM

mysqli is not the database, it's only the function.
You shoukd always use mysqli for connecting to a mysql database.
Mysqli is the new version of the function mysql.

Have you tried to simply execute this code?
(or course, you will have to change the connection string)
  • 0

#3 Eteken

Eteken

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 02 April 2013 - 08:07 AM

You can use all MYSQLi functionalities in a non MYSQLi supporting server by using a handwritten MYSQLi Class. 
 
Using this class you dont need to change your code. Just include the mysqli library php file.
 

Edited by Eteken, 02 April 2013 - 08:08 AM.

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download