mysql_query error
-
Hello all. Am having a major problem with my code.I cant find an error in the code but i keep getting this messages "Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 223 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 251 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 194 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 195 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 261 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203" and the php code is
<?php
/** this is the database connections specification files
can only be changed by an administrator
*/
//connect to databaserequire\_once("constants.php"); class MySQLDB { var $connection; //the mysql database connection var $num\_active\_user; //number of active users viewing site var $num\_active\_guests; //number of guests viewing site var $num\_members; //number of signed users //class constructor function MySLQDB() { $this->connection = mysql\_connect(DB\_SERVER, DB\_USER, DB\_PASS) or die (mysql\_error()); mysql\_select\_db(DB\_NAME, $this->connection) or die(mysql\_error()); //only query database to find out number of members when getnummembers() is called for the first time, until then //default value is set $this->num\_members = -1; if(TRACK\_VISITORS) { //calculate number of users at site $this->calcNumActiveUsers(); //calculate number of guests at site $this->calcNumActiveGuests(); } } //confirm users pass function confirmUserpass($username, $password) { //add slashes if necessary if(!get\_magic\_quotes\_gpc()) { $username =
-
Hello all. Am having a major problem with my code.I cant find an error in the code but i keep getting this messages "Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 223 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 251 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 194 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 195 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 261 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203" and the php code is
<?php
/** this is the database connections specification files
can only be changed by an administrator
*/
//connect to databaserequire\_once("constants.php"); class MySQLDB { var $connection; //the mysql database connection var $num\_active\_user; //number of active users viewing site var $num\_active\_guests; //number of guests viewing site var $num\_members; //number of signed users //class constructor function MySLQDB() { $this->connection = mysql\_connect(DB\_SERVER, DB\_USER, DB\_PASS) or die (mysql\_error()); mysql\_select\_db(DB\_NAME, $this->connection) or die(mysql\_error()); //only query database to find out number of members when getnummembers() is called for the first time, until then //default value is set $this->num\_members = -1; if(TRACK\_VISITORS) { //calculate number of users at site $this->calcNumActiveUsers(); //calculate number of guests at site $this->calcNumActiveGuests(); } } //confirm users pass function confirmUserpass($username, $password) { //add slashes if necessary if(!get\_magic\_quotes\_gpc()) { $username =
I can't be 100% sure but it sounds like the constructor method is never actually called. I believe this because $this->connection is null when passed to the mysql_query method. The only reason I can think of is if the constructor is not called, if it had been and failed to initialize you would get an invalid resource exception. Try renaming it to:
function __construct()
{
// your previous constructor code
}