...

View Full Version : arcade_db->query not working



sitNsmile
03-24-2010, 09:25 PM
Okay. trying to find out why the query isnt working, the database is loaded and functions are included.


query I want to load. (just doesnt seem to work)


$sql_query = "SELECT * FROM games_info WHERE g_id = $g_id AND g_status = 1 LIMIT 1";
$sql_result = mysql_query($arcade_db->query($sql_query));


in the config.php (connect DB)

$arcade_db = new mysql;
$arcade_db->connect('IP', 'USER', 'PASS', 'DB');


in the mysql.php (class)



class mysql {

var $link=null;

function connect($host, $user, $pass, $db) {
$this->link = mysql_connect($host, $user, $pass) or die("SQL Connection Error");
mysql_select_db($db, $this->link) or die("SQL Database Selection Error");
}

function query($query) {

$result = mysql_query($query, $this->link);

if (!($result)) {
ob_end_clean();
die("SQL Error: ".mysql_error($this->link)."<br /> Query: $query<br />");
}
return $result;
}
}


Thanks

Fou-Lu
03-24-2010, 09:50 PM
You're trying to query a query here: $sql_result = mysql_query($arcade_db->query($sql_query)); . Remove the outter mysql_query, you'll need to either use a custom iterator for fetching, or the equivilent database (mysql in this case) function for fetch.

Dormilich
03-24-2010, 10:52 PM
out of curiousity, why using this mysql class when you can use the MySQLi class?

sitNsmile
03-25-2010, 12:48 AM
You're trying to query a query here: $sql_result = mysql_query($arcade_db->query($sql_query)); . Remove the outter mysql_query, you'll need to either use a custom iterator for fetching, or the equivilent database (mysql in this case) function for fetch.


Thank you. I didn't even notice I was trying to double query.

sitNsmile
03-25-2010, 12:50 AM
out of curiousity, why using this mysql class when you can use the MySQLi class?


Thats because I've tried out the mysqli and it never worked for me, I am thinking maybe its my clients server that doesn't allow that yet.

Fou-Lu
03-25-2010, 12:59 AM
Thats because I've tried out the mysqli and it never worked for me, I am thinking maybe its my clients server that doesn't allow that yet.

That is definitely possible. The custom MySQL class written here was also from an older version of php (notice the use of the var keyword for members instead of the public/private/protected scope of PHP5+). MySQLi interfacing itself requires PHP5+ AND MySQL 4.1.13+.
Now, this likely was, and possibly still is the limiting factor for why the MySQLi is not in use. If I were you sitNsmile, I would actually look at interfacing everything on you're current class to match the definitions of the MySQLi class. This is a matter of simply renaming necessary functions (both in the class and in calls) and adding / removing / modifying necessary code to match the MySQLi method signatures. Level of work involved would be dependant on the size of you're project itself, but I can assure you (assuming you're using a local development environment in case you need to blow it away), this will actually be more search and replace than anything.
What you gain: given the sufficient technology, an immediate drop from new MySQL(...); to new MySQLi(...); without needing to alter any other code.

sitNsmile
03-25-2010, 01:10 AM
That is definitely possible. The custom MySQL class written here was also from an older version of php (notice the use of the var keyword for members instead of the public/private/protected scope of PHP5+). MySQLi interfacing itself requires PHP5+ AND MySQL 4.1.13+.
Now, this likely was, and possibly still is the limiting factor for why the MySQLi is not in use. If I were you sitNsmile, I would actually look at interfacing everything on you're current class to match the definitions of the MySQLi class. This is a matter of simply renaming necessary functions (both in the class and in calls) and adding / removing / modifying necessary code to match the MySQLi method signatures. Level of work involved would be dependant on the size of you're project itself, but I can assure you (assuming you're using a local development environment in case you need to blow it away), this will actually be more search and replace than anything.
What you gain: given the sufficient technology, an immediate drop from new MySQL(...); to new MySQLi(...); without needing to alter any other code.


Thank you. I will build a 2nd version calling it mysqli.php and test out both.

But on a note, what are the advantages of having mysqli instead of mysql class?

Dormilich
03-25-2010, 08:37 AM
But on a note, what are the advantages of having mysqli instead of mysql class?

MySQLi is native PHP code (runs faster) and has a lot of useful methods, including
- Prepared Statements
- Transactions
- Database Information
- Query Information
thereís nearly nothing about MySQL you canít find out with MySQLi.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum