* @author Tobias Leupold
*/
-class b8_storage_mysql extends b8_storage_base
+class b8_storage_frndc extends b8_storage_base
{
public $config = array(
private $_deletes = array();
private $_puts = array();
private $_updates = array();
+ private $uid = 0;
const DATABASE_CONNECTION_FAIL = 'DATABASE_CONNECTION_FAIL';
const DATABASE_CONNECTION_ERROR = 'DATABASE_CONNECTION_ERROR';
public function connect()
{
+ return TRUE;
+
# Are we already connected?
if($this->connected === TRUE)
return TRUE;
* @return mixed Returns an array of the returned data in the format array(token => data) or an empty array if there was no data.
*/
- protected function _get_query($tokens)
+ protected function _get_query($tokens, $uid)
{
# Construct the query ...
$where = array();
foreach ($tokens as $token) {
- $token = mysql_real_escape_string($token, $this->_connection);
+ $token = dbesc($token);
array_push($where, $token);
}
}
else {
- $token = mysql_real_escape_string($token, $this->_connection);
+ $token = dbesc($token);
$where = 'token = "' . $token . '"';
}
# ... and fetch the data
- $result = mysql_query('
+ $result = q('
SELECT token, count
FROM ' . $this->config['table_name'] . '
- WHERE ' . $where . ';
- ', $this->_connection);
-
- $data = array();
-
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
- $data[$row['token']] = $row['count'];
-
- mysql_free_result($result);
+ WHERE ' . $where . ' AND uid = ' . $uid );
- return $data;
+ return $result;
}
* @return void
*/
- protected function _put($token, $count) {
- $token = mysql_real_escape_string($token, $this->_connection);
- $count = mysql_real_escape_string($count, $this->_connection);;
- array_push($this->_puts, '("' . $token . '", "' . $count . '")');
+ protected function _put($token, $count, $uid) {
+ $token = dbesc($token);
+ $count = dbesc($count);
+ $uid = dbesc($uid);
+ array_push($this->_puts, '("' . $token . '", "' . $count . '", '"' . $uid .'")');
}
/**
* @return void
*/
- protected function _update($token, $count)
+ protected function _update($token, $count, $uid)
{
- $token = mysql_real_escape_string($token, $this->_connection);
- $count = mysql_real_escape_string($count, $this->_connection);
- array_push($this->_updates, '("' . $token . '", "' . $count . '")');
+ $token = dbesc($token);
+ $count = dbesc($count);
+ $uid = dbesc($uid);
+ array_push($this->_puts, '("' . $token . '", "' . $count . '", '"' . $uid .'")');
}
/**
* @return void
*/
- protected function _del($token)
+ protected function _del($token, $uid)
{
- $token = mysql_real_escape_string($token, $this->_connection);
+ $token = dbesc($token);
+ $uid = dbesc($uid);
+ $this->uid = $uid;
array_push($this->_deletes, $token);
}
* @return void
*/
- protected function _commit()
+ protected function _commit($uid)
{
if(count($this->_deletes) > 0) {
- $result = mysql_query('
+ $result = q('
DELETE FROM ' . $this->config['table_name'] . '
- WHERE token IN ("' . implode('", "', $this->_deletes) . '");
- ', $this->_connection);
-
- if(is_resource($result) === TRUE)
- mysql_free_result($result);
+ WHERE token IN ("' . implode('", "', $this->_deletes) . '") AND uid = ' . $this->uid);
$this->_deletes = array();
if(count($this->_puts) > 0) {
- $result = mysql_query('
- INSERT INTO ' . $this->config['table_name'] . '(token, count)
- VALUES ' . implode(', ', $this->_puts) . ';', $this->_connection);
-
- if(is_resource($result) === TRUE)
- mysql_free_result($result);
+ $result = q('
+ INSERT INTO ' . $this->config['table_name'] . '(token, count, uid)
+ VALUES ' . implode(', ', $this->_puts));
$this->_puts = array();
if(count($this->_updates) > 0) {
- $result = mysql_query('
- INSERT INTO ' . $this->config['table_name'] . '(token, count)
- VALUES ' . implode(', ', $this->_updates) . '
- ON DUPLICATE KEY UPDATE ' . $this->config['table_name'] . '.count = VALUES(count);', $this->_connection);
+ // this still needs work
+ $result = q("select * from " . $this->config['table_name'] . ' where token = ';
- if(is_resource($result) === TRUE)
- mysql_free_result($result);
+
+ $result = q('
+ INSERT INTO ' . $this->config['table_name'] . '(token, count, uid)
+ VALUES ' . implode(', ', $this->_updates) . ', ' . $uid . '
+ ON DUPLICATE KEY UPDATE ' . $this->config['table_name'] . '.count = VALUES(count);', $this->_connection);
$this->_updates = array();