Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to 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 - 05:47 PM

I found a autosuggest code, but the connection to database is mysqli, so I edit the syntax to mysql_connect..

Here is the original 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 :(';
}
} else {
// do nothing
}
} else {
echo 'There should be no direct access to this script!';
}
}
?>


and I edit it:


<?php
$db_host = 'localhost';
$db_user = 'root';
$db_password = '';
$db_name = 'db_upload';


$db = mysql_connect($db_host , $db_user ,$db_password, $db_name);

if(isset($_POST['queryString'])) {
$queryString = mysql_real_escape_string($_POST['queryString']);

if(strlen($queryString) >0) {

$query = mysql_query("SELECT country FROM countries WHERE country LIKE '$queryString%' LIMIT 10");
if($query) {
echo '<ul>';
while ($result = mysql_fetch_object($query)) {
echo '<li onClick="fill(\''.addslashes($result->country).'\');">'.$result->country.'</li>';
}
echo '</ul>';

} else {
echo 'OOPS we had a problem :(';
}
} else {
// do nothing
}
} else {
echo 'There should be no direct access to this script!';
}
?>


when i run it, it was always fall in else statement

'OOPS we had a problem :('
even I input correct data.

here is the link where I found the code:
jQuery PHP Ajax Autosuggest | Ashley Ford - Tutorials :: jQuery :: PHP :: CSS :: HTML5 :: Papermashup.com

Thank you
  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 27 October 2011 - 09:24 PM

And your php don't support MySQLi? MySQLi is just another version of the MySQL-driver in php, where i stands for improved. it's better to use MySQLi if possible. just keep it if you can. it works just as good with the same server.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 27 October 2011 - 09:55 PM

Yes, my php doesn't support mysqli, so i tried to change the syntax, from mysqli to mysql


Thank you
  • 0





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