public static function isReservedUsername($s) { $s = trim($s); $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE type = ?' . ' AND value = ?'; $val = Sql::pSelectItem($q, 'is', RESERVED_USERNAME, $s); if ($val) { return true; } return false; }
/** Adds the user to a user group */ public static function addToGroup($user_id, $grp_id) { $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE groupId = ? AND userId = ?'; if (Sql::pSelectItem($q, 'ii', $grp_id, $user_id)) { return true; } $q = 'INSERT INTO ' . self::$tbl_name . ' SET groupId = ?, userId = ?'; Sql::pInsert($q, 'ii', $grp_id, $user_id); return true; }
/** Has current user rated item/answered poll? */ static function hasAnswered($type, $id) { $session = SessionHandler::getInstance(); if (!$session->id) { return true; } $q = 'SELECT owner FROM ' . self::$tbl_name . ' WHERE type = ? AND userId = ? AND owner = ?'; if (Sql::pSelectItem($q, 'iii', $type, $session->id, $id)) { return true; } return false; }
public function store() { $q = 'SELECT id FROM ' . self::$tbl_name . ' WHERE owner = ? AND season = ? AND episode = ?'; $this->id = Sql::pSelectItem($q, 'iii', $this->owner, $this->season, $this->episode); if ($this->id) { $q = 'UPDATE ' . self::$tbl_name . ' SET owner = ?, title = ?, date = ?, info = ?, season = ?, episode = ?, link = ? WHERE id = ?'; Sql::pUpdate($q, 'isssiisi', $this->owner, $this->title, $this->date, $this->info, $this->season, $this->episode, $this->link, $this->id); return $this->id; } $q = 'INSERT INTO ' . self::$tbl_name . ' SET owner = ?, title = ?, date = ?, info = ?, season = ?, episode = ?, link = ?'; return Sql::pInsert($q, 'isssiis', $this->owner, $this->title, $this->date, $this->info, $this->season, $this->episode, $this->link); }
/** @return number of unread messages in the Inbox */ public static function getUnreadCount($user_id) { $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE `to` = ? AND time_read IS NULL' . ' ORDER BY time_sent DESC'; return Sql::pSelectItem($q, 'i', $user_id); }
$q = 'SHOW GRANTS FOR CURRENT_USER'; $priv = Sql::pSelect($q); // ex: GRANT USAGE ON *.* TO 'savak'@'%' IDENTIFIED BY PASSWORD '*0... // ex: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*xxx' // ex: GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*xxx' WITH GRANT OPTION /// XXXXX FIXME: censor password from string instead of cut it!!!! //d($priv); echo '<h2>Privileges</h2>'; foreach ($priv as $p) { $key = key($p); $val = current($p); echo $key . ': <b>' . substr($val, 0, 60) . '</b>...<br/>'; } echo '<br/>'; echo '<h2>Time</h2>'; $db_time = Sql::pSelectItem('SELECT NOW()'); echo 'Database time: ' . $db_time . '<br/>'; echo 'Webserver time: ' . now() . '<br/>'; $uptime = Sql::pSelectRow('SHOW STATUS WHERE Variable_name = ?', 's', 'Uptime'); echo 'Database uptime: <b>' . elapsed_seconds($uptime['Value']) . '</b><br/>'; echo '<br/>'; echo '<h2>Character sets</h2>'; $charsets = Sql::pSelectMapped('SHOW VARIABLES LIKE "%character_set%"'); foreach ($charsets as $ch_name => $val) { echo $ch_name . ' = '; if (!in_array($val, array('utf8'))) { echo '<font color="red">' . $val . '</font>'; } else { echo $val; } echo '<br/>';
public static function getStatusByReference($type, $reference) { $q = 'SELECT approved FROM ' . self::$tbl_name . ' WHERE type = ? AND reference = ?'; return Sql::pSelectItem($q, 'ii', $type, $reference); }
public static function isLiked($owner, $type, $user_id) { $q = 'SELECT id FROM ' . self::$tbl_name . ' WHERE owner = ? AND type = ? AND user = ?'; $id = Sql::pSelectItem($q, 'iii', $owner, $type, $user_id); return $id ? true : false; }
public static function getName($id) { $q = 'SELECT name FROM ' . self::$tbl_name . ' WHERE id = ?' . ' AND time_deleted IS NULL'; return Sql::pSelectItem($q, 'i', $id); }
public static function getUnseenCount($to) { $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE `to` = ?'; return Sql::pSelectItem($q, 'i', $to); }
public function read($id) { $q = 'SELECT session_data FROM tblSessionData WHERE session_id = ? AND expires > ?'; return Sql::pSelectItem($q, 'ss', $id, sql_datetime(time())); }
function save() { $session = SessionHandler::getInstance(); if (!$this->id) { $q = 'SELECT groupId FROM tblUserGroups WHERE name = ?'; $this->id = Sql::pSelectItem($q, 's', $this->name); } if ($this->id) { $q = 'UPDATE tblUserGroups SET name = ?, info = ?, level = ? WHERE groupId = ?'; Sql::pUpdate($q, 'ssii', $this->name, $this->info, $this->level, $this->id); } else { $q = 'INSERT INTO tblUserGroups SET createdBy = ?, timeCreated = NOW(), name = ?, info = ?, level = ?'; $this->id = Sql::pInsert($q, 'issi', $session->id, $this->name, $this->info, $this->level); } return $this->id; }
/** * Compares the object:s set properties to table columns * @return true if object exists **/ public static function exists($obj, $tblname) { if (!is_alphanumeric($tblname)) { throw new \Exception('very bad'); } $reflect = self::reflectQuery($obj, '', false); $q = 'SELECT COUNT(*) FROM ' . $tblname . ' WHERE ' . implode(' AND ', $reflect->cols); return Sql::pSelectItem($q, $reflect->str, $reflect->vals) ? true : false; }
public static function SubjectExists($type, $subject) { $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE type = ? AND subject = ?'; $cnt = Sql::pSelectItem($q, 'is', $type, $subject); return $cnt ? true : false; }
public static function getCount($type, $owner) { $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE type = ? AND owner = ?'; return Sql::pSelectItem($q, 'ii', $type, $owner); }
/** * @return number of users online */ public static function onlineCount() { $session = SessionHandler::getInstance(); $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE time_deleted IS NULL' . ' AND time_last_active >= DATE_SUB(NOW(),INTERVAL ' . $session->online_timeout . ' SECOND)'; return Sql::pSelectItem($q); }
/** * Used by Token class */ public static function getTimeSaved($type, $name, $val) { $q = 'SELECT time_saved FROM ' . self::$tbl_name . ' WHERE type = ? AND name = ? AND value = ?'; return Sql::pSelectItem($q, 'iss', $type, $name, $val); }