/** * @param $duration_mode "1d", "2w", "2m" */ static function add($type, $owner, $text, $duration_mode = '', $start_mode = '') { $length = parse_duration($duration_mode); if (!$length) { throw new \Exception('odd duration ' . $duration_mode); } switch ($start_mode) { case 'thismonday': $dayofweek = date('N'); $mon = date('n'); $day = date('j'); $timeStart = mktime(6, 0, 0, $mon, $day - $dayofweek + 1); //06:00 Monday current week break; case 'nextmonday': $dayofweek = date('N'); $mon = date('n'); $day = date('j'); $timeStart = mktime(6, 0, 0, $mon, $day - $dayofweek + 1 + 7); //06:00 Monday next week break; case 'nextfree': $q = 'SELECT time_end FROM tblPolls' . ' WHERE owner = ? AND deleted_by = ?' . ' ORDER BY time_start DESC' . ' LIMIT 1'; $data = Sql::pSelectRow($q, 'ii', $owner, 0); $timeStart = $data ? ts($data['timeEnd']) : time(); break; default: throw new \Exception('eexp'); } $timeEnd = $timeStart + $length; return self::addPollExactPeriod($type, $owner, $text, $timeStart, $timeEnd); }
public static function get($type, $owner, $name, $default = '') { $q = 'SELECT value FROM ' . self::$tbl_name . ' WHERE owner = ? AND type = ? AND name = ?'; $res = Sql::pSelectRow($q, 'iis', $owner, $type, $name); if ($res) { return $res['value']; } return $default; }
// 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/>'; } $collations = Sql::pSelectMapped('SHOW VARIABLES LIKE "%collation%"'); foreach ($collations as $ch_name => $val) {
public static function getByReference($type, $reference) { $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE type = ? AND reference = ?'; $row = Sql::pSelectRow($q, 'ii', $type, $reference); return SqlObject::loadObject($row, __CLASS__); }
public static function getLatestByOwner($type, $owner) { $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE type = ? AND owner = ?' . ' ORDER BY time_saved DESC' . ' LIMIT 1'; $row = Sql::pSelectRow($q, 'ii', $type, $owner); return SqlObject::loadObject($row, __CLASS__); }
public static function get($id) { $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE id = ?' . ' AND time_deleted IS NULL'; $row = Sql::pSelectRow($q, 'i', $id); return SqlObject::loadObject($row, __CLASS__); }
d($x); $q = 'REPLACE tblSessionData (session_id,session_data,expires) VALUES(?, ?, ?)'; $xxx = Sql::pUpdate($q, 'sss', 666, "hejhej", sql_datetime( time() ) ); d($xxx); $q = 'INSERT INTO tblLikes (owner,type) VALUES (?, ?)'; $id = Sql::pInsert($q, 'ii', 4,9); if ($id < 2) echo "FAIL 5\n"; $w = new Word(); $w->id = 8; $w->value = "sten"; if (SqlObject::exists($w, 'oWord') != true) echo "FAIL 10\n"; $w = new Word(); $w->id = 8; $w->value = "st2en"; if (SqlObject::exists($w, 'oWord') == true) echo "FAIL 11\n"; */ // TODO more reliable test of ListToObjects $q = 'SELECT * FROM tblBookmarks' . ' WHERE owner = ? AND type = ?'; $list = Sql::pSelect($q, 'ii', 2, 100); $objs = SqlObject::ListToObjects($list, 'Bookmark'); if (count($objs) < 5) { echo "FAIL 20\n"; } $q = 'SELECT * FROM tblBookmarks' . ' WHERE id = ?'; $row = Sql::pSelectRow($q, 'i', 66); $obj = SqlObject::RowToObject($row, 'Bookmark'); if ($obj->id != 66) { echo "FAIL 30\n"; } $bb = Bookmark::get(66); d($bb);
public static function getByName($s) { $q = 'SELECT * FROM tblUserGroups WHERE name = ?'; return Sql::pSelectRow($q, 's', $s); }
public static function getByOwner($id) { $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE owner = ?' . ' ORDER BY time_saved DESC' . ' LIMIT 1'; $res = Sql::pSelectRow($q, 'i', $id); return SqlObject::loadObject($res, __CLASS__); }