|
Step 3: Creating Data Access Methods
Concrete and backend specific methods go into the driver
implementation class e.g. Mopple_Driver_sql in lib/Driver/sql.php.
<?php class Mopple_Driver_sql extends Mopple_Driver {
/** * Retrieves the MP3s from the database. * * @return boolean|PEAR_Error True on success, PEAR_Error on failure. */ function retrieve() { /* Make sure we have a valid database connection. */ $this->_connect();
/* Build the SQL query. */ $query = sprintf('SELECT * FROM %s WHERE song_owner = %s', $this->_params['table'], $this->_db->quote(Auth::getAuth()));
/* Log the query at a DEBUG log level. */ Horde::logMessage(sprintf('Mopple_Driver_sql::retrieve(): %s', $query), __FILE__, __LINE__, PEAR_LOG_DEBUG);
/* Execute the query. */ $result = $this->_db->query($query);
if (isset($result) && !is_a($result, 'PEAR_Error')) { $row = $result->fetchRow(DB_FETCHMODE_ASSOC); if (is_a($row, 'PEAR_Error')) { return $row; }
/* Store the retrieved values in the $_mp3s variable. */ $this->_mp3s = array(); while ($row && !is_a($row, 'PEAR_Error')) { /* Add this new task to the $tasks list. */ $this->_mp3s[] = $row;
/* Advance to the new row in the result set. */ $row = $result->fetchRow(DB_FETCHMODE_ASSOC); } $result->free(); } else { return $result; }
return true; } ?>
|