i'm trying to have my MYSQL encapsulated so that if i need to make changes and all that it's easy and it's in a function already. the problem is that i can't seem to get it to work.
here is the code for my class so far:
lass.spuds.php
class spuds_db
{
function sql_db($server, $user, $password, $database)
{
mysql_connect('localhost', 'testing', 'loot');
mysql_select_db('user_auth') or die( "Unable to select database. <B>MySQL ERROR</B> = " . mysql_error());
}
function query($query) { mysql_query($query); }
function num_rows($result) { return mysql_num_rows($result); }
};
here is my init for calling that class:
$db = new spuds_db;
$db->sql_db($host, $username, $password, $database);
know i know. i hardcoded the stuff in there but it didn't seem to connect until i did this anyways. that's a side note, if you can figure that out you'd be awesome
this is the file that is giving me problems
register.php
$sql_email_check = $db->query("SELECT email_address FROM users WHERE email_address='$email_address'");
$sql_username_check = $db->query("SELECT username FROM users WHERE username='$username'");
$email_check = $db->num_rows($sql_email_check);
$username_check = $db->num_rows($sql_username_check);
and this is the problem:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Developer\apachefriends\xampp\htdocs\member\classes\class.spuds_db.php on line 56
see, i know that what i'm doing is very close to right but i can't seem to figure out WHY it's failing on me. it's a warning so it does update and put it into the DB but it seems to still crackup when i refresh and all that. it's really starting to bother me
yes, i am testing locally. i'm building a CMS from scratch as a personal project and using a better well developed one for professional use.
thanx for your help