PEAR DB normally works fine for me but I'm trying to write a simple dummie class to test how it works within a class. I'm currently reading PHP mySQL Website Programing: Problem - Design - Solution from Wrox so that's where I'm learning most of this stuff.. Any way let me show you the code first.
Code:
<?php
/************************
* CLASS.SESSION.PHP
* Handles user login.
************************/
require_once("DB.php");
class session {
var $_strUserName;
var $_strUserPass;
var $_objConn;
var $_objMail;
// Class constructor...
function session($name=' ',$pass=' ') {
$this->_objConn =& DB::connect(DSN);
if($_strUserName == ' ') {
// Ensures a username was submitted...
$this->_error("No user name was specified.");
return FALSE;
} else {
$this->_strUserName = $name;
$this->_strUserPass = $pass;
$this->_authenticate();
}
}
// Authenticates the user...
function _authenticate() {
$sql = "SELECT admin_id,admin_pass FROM administrators WHERE admin_name=" . $this->_strUserName;
echo $sql;
$objRS = $this->_objConn->query($sql);
$objRow = $objRS->fetchRow(DB_FETCHMODE_ASSOC);
if($objRS->numRows() < 1) {
$this->_error("The user name you entered does not exist.");
return FALSE;
} elseif($objRS['admin_pass'] != $this->_strUserPass) {
$this->_error("The password you entered is incorrect.");
return FALSE;
} else {
echo "<p><strong>CONGRATULATIONS!</strong><br/>You have successfully logged into the site as: " . $this->_strUserName . "</p>";
}
}
// Generates an error...
function _error($strMessage) {
echo "<p><strong class=\"error\">ERROR you could no be logged:</strong><br>";
echo $strMessage;
}
}
?>
I know for a fact that the Pear object is working up to the point fetchRow is called becuase when I echo $objRS I get the response 'Object' as output. But for some reason the page generates a fatal error saying the function fetchrow is undefined... does anyone know what I can do?
- Jim J.