コード例 #1
0
ファイル: Bookmark.php プロジェクト: martinlindhe/core_dev
 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__);
 }
コード例 #2
0
ファイル: Comment.php プロジェクト: martinlindhe/core_dev
 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__);
 }
コード例 #3
0
ファイル: test.Sql.php プロジェクト: martinlindhe/core_dev
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);
コード例 #4
0
ファイル: SqlObject.php プロジェクト: martinlindhe/core_dev
 /**
  * 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);
 }