Databases Reference
In-Depth Information
Database class
We created a database class, Database.php, where we implemented the
following functions:
__construct()
This is the database class constructor function to initialize both the dbAdapter
connection object and the XMLContentStore connection object.
Note: $conn is the connection object of the DB2 database we created in
our bootstrap file www/index.php.
Example 3-26 shows __construct().
Example 3-26 Database class: constructor method
private $_db;
private $_db1;
public function __construct($conn)
{
$this → _db = $conn; // for dbAdapter
// for XML Content store
$this → _db1 = new Zend_Db_Xml_XmlContentStore_Db2($conn);
}
login()
This method provides the SQL query to go against the member database to
check if the user profile exists. Also, it returns a member's ID so that the
member's detailed profile can be fetched from XCS. Example 3-27 shows the
login() method.
Example 3-27 Database class: login method
public function login($email, $passwd)
{
$sql = "SELECT xmlid, fname, lname from member where email=
? and passwd= ?";
$param = array(); // an array is created for parameters
$param[]= $email;
$param[]= $passwd;
if ($result = $this → _db → fetchAssoc($sql, $param)) {
return $result;
}
return FALSE;
}
Search WWH ::




Custom Search