i tried to write a class for easy mysql db access, but something is going wrong and i can't figure out what. so any help would be nice.
the code:
class myMySQL {
var $connection;
function myMySQL () {
$this->connection = mysql_connect (
MYSQL_SERVER,
MYSQL_USER,
MYSQL_PASSWORD
) || die 'fehler';
return true;
}
function query ($_query) {
if ($_query != '') {
$_return = mysql_db_query (
MYSQL_DB,
$_query,
$this->connection
) || die 'fehler';
}
return $_return;
}
}
that's the class (all constants are defined earlier). now when i try to do the following, an error occurs:
$mysqltest = new myMySQL ();
$return = $mysqltest->query ("SELECT * FROM table_name");
$temp = mysql_fetch_array ($return);
output:
Warning: Supplied argument is not a valid MySQL-Link resource in e:\server\Projects\gtol_classes\mymysql.class.php on line 31
Warning: Supplied argument is not a valid MySQL result resource in e:\server\projects\gtol\test.php on line 16
(the first file contains the class definition, the second is the calling script).
if anyone know what's wrong, please let me know,
thank you