Beispiel #1
0
 public static function getList($type, $owner)
 {
     if (!is_numeric($owner) || !is_numeric($type)) {
         throw new \Exception('noo');
     }
     $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE owner = ? AND type = ?';
     $list = Sql::pSelect($q, 'ii', $owner, $type);
     return SqlObject::ListToObjects($list, __CLASS__);
 }
Beispiel #2
0
 public static function getByType($type)
 {
     if (!is_numeric($type)) {
         throw new \Exception('hmmm');
     }
     $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE type = ?' . ' ORDER BY time_created DESC';
     $list = Sql::pSelect($q, 'i', $type);
     return SqlObject::ListToObjects($list, __CLASS__);
 }
Beispiel #3
0
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);
Beispiel #4
0
 /**
  * Fetches all items where $field_name = $value
  * @param $field_name
  * @param $value
  * @param $tblname
  * @param $classname
  * @param $order_field
  * @param $order 'desc', 'asc' or empty
  */
 public static function getAllByField($field_name, $value, $tblname, $classname, $order_field = '', $order = 'asc')
 {
     if (!is_alphanumeric($tblname)) {
         throw new \Exception('tblname should be alphanumeric, isnt: ' . $tblname);
     }
     if (!is_alphanumeric($field_name)) {
         throw new \Exception('field_name should be alphanumeric, isnt: ' . $field_name);
     }
     if (!is_alphanumeric($order_field)) {
         throw new \Exception('order_field should be alphanumeric, isnt: ' . $order_field);
     }
     if (!Sql::isValidOrder($order)) {
         throw new \Exception('odd order ' . $order);
     }
     $form = self::stringForm($value);
     $q = 'SELECT * FROM ' . $tblname . ' WHERE ' . $field_name . ' = ?' . ($order_field ? ' ORDER BY ' . $order_field . ' ' . strtoupper($order) : '');
     $list = Sql::pSelect($q, $form, $value);
     return SqlObject::ListToObjects($list, $classname);
 }