Hi all.
This is the database class I've created myself. While fetching seems to work OK, the functions which reference the result set and such bomb out with the error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in classes.php on line 57
I'm at a bit of a loss to diagnose the problem.
This is the database class in full:
Class Database
{
Var $Link, $Result, $Query;
Function Database( $Host , $User , $Password , $Name )
{
$this->Host = $Host;
$this->User = $User;
$this->Password = $Password;
$this->Name = $Name;
$this->Connect( $this->Host , $this->User , $this->Password );
$this->SelectDB( $this->Name );
if (mysql_error()) print mysql_error();
}
Function Connect( $Host , $User , $Password )
{
$this->Link = mysql_connect( $Host , $User , $Password );
}
Function Close()
{
mysql_close( $this->Link );
}
Function SelectDB( $Database )
{
mysql_select_db( $Database, $this->Link );
}
Function Query( $Query )
{
$this->Query = $Query;
$this->Result = mysql_query( $this->Query , $this->Link );
}
Function GetRow()
{
Return mysql_fetch_array( $this->Result );
}
Function NumRows() {
Return mysql_num_rows( $this->Result );
}
Function AffectedRows() {
Return mysql_affected_rows( $this->Link );
}
Function Error()
{
Return mysql_error();
}
}
This is the portion of my 'category' class which tries to set the name in the database, and is failing:
Function SetName( $NewName )
{
$NewName = addslashes( strip_tags( $NewName ) );
$this->Database->Query( "UPDATE Category SET Name = '$NewName' WHERE ID = '$this->ID'" );
if ( $this->Database->NumRows() ) {
$this->Name = $NewName;
Return True;
} else {
$this->Error = "SetName: Could not set name";
Return False;
}
}
Many thanks in advance 😃