insert() public static method

public static insert ( $table, $args ) : Dibi\Fluent
return Dibi\Fluent
コード例 #1
0
 /**
  * translates string with key $msg_id
  *
  * @param string $msg_id
  * @param int $count NOT USED YET, only for ITranslator needs
  * @return string translated string
  */
 public function translate($msg_id, $count = NULL)
 {
     if ($msg_id == "") {
         return NULL;
     }
     ///**************
     if (!isset($this->dictionary[$msg_id])) {
         dibi::insert(self::TABLE, array('msg_id' => $msg_id))->execute();
         $this->dictionary[$msg_id] = $msg_id;
         CacheTools::invalidate('dictionary');
     }
     /**	applying parameters **/
     $args = func_get_args();
     $argsCount = count($args);
     $requiredArgsCount = preg_match_all($this->paramsRegexp, $this->dictionary[$msg_id], $matches);
     if ($requiredArgsCount > $argsCount - 1) {
         throw new InvalidArgumentException("Insufficient number of arguments in translate function. Provided string '{$msg_id}'");
     }
     //        if ($argsCount > 1) {
     //	volane z Rules.php, aby sa mi to nesexovalo s '%label' a tym percentom a nemusel ho zdvojovat
     if ($argsCount > 1 && !is_null($args[1])) {
         //	vola sa to aj s parametrami z Rules.php napr. pre MIN_LENGTH a pod., treba zdvojit percento
         $msg_id = str_replace(array('%label', '%name', '%value'), array('%%label', '%%name', '%%value'), $this->dictionary[$msg_id]);
         //		dump($args);
         array_shift($args);
         //		dump($args);
         return vsprintf($msg_id, $args);
     } else {
         return $this->dictionary[$msg_id];
     }
     /**	applying parameters END **/
 }
コード例 #2
0
ファイル: ConfigSet.php プロジェクト: killsaw/Mescal
 public function __set($name, $value)
 {
     if (!array_key_exists($name, $this->vars)) {
         dibi::insert("configs", array('name' => $name, 'value' => $value))->execute();
         return $this->vars[$name] = $value;
     } else {
         if ($this->vars[$name] == $value) {
             return $value;
         }
         dibi::update("configs", array('value' => $value))->where('name=%s', $name)->execute();
         return $this->vars[$name] = $value;
     }
 }
コード例 #3
0
ファイル: RolesModel.php プロジェクト: radypala/maga-website
 /**
  * update user roles [delete & insert]
  *
  * @param int User id
  * @param int Role id
  */
 public function updateUserRoles($userId, $roles)
 {
     try {
         dibi::begin();
         dibi::delete(self::ACL_USERS_2_ROLES_TABLE)->where('user_id = %i', $userId)->execute();
         foreach ($roles as $role) {
             dibi::insert(self::ACL_USERS_2_ROLES_TABLE, array('user_id' => $userId, 'role_id' => $role))->execute();
         }
         dibi::commit();
     } catch (DibiDriverException $e) {
         dibi::rollback();
         throw $e;
     }
 }
コード例 #4
0
ファイル: group.class.php プロジェクト: roesel/lolcomp
 function insertIntoDatabase($id, $name, $region)
 {
     $codename = strtolower(preg_replace('/\\s+/', '', $name));
     // player name
     $row = array("codename" => $codename, "id" => $id, "region" => $region, "last_updated" => NULL);
     $table = "group";
     dibi::insert($table, $row)->on('DUPLICATE KEY UPDATE %a ', $row)->execute();
 }
コード例 #5
0
ファイル: Logs.php プロジェクト: bozhich/PHP-on-Rails
 public static function insert($data, $log_type)
 {
     return dibi::insert(self::getTable($log_type), $data)->execute();
 }
コード例 #6
0
ファイル: using-fluent-syntax.php プロジェクト: kravco/dibi
<h1>Using Fluent Syntax | dibi</h1>

<?php 
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb'));
$id = 10;
$record = array('title' => 'Super product', 'price' => 318, 'active' => TRUE);
// SELECT ...
dibi::select('product_id')->as('id')->select('title')->from('products')->innerJoin('orders')->using('(product_id)')->innerJoin('customers USING (customer_id)')->orderBy('title')->test();
// -> SELECT [product_id] AS [id] , [title] FROM [products] INNER JOIN [orders]
//    USING (product_id) INNER JOIN customers USING (customer_id) ORDER BY [title]
// SELECT ...
echo dibi::select('title')->as('id')->from('products')->fetchSingle();
// -> Chair (as result of query: SELECT [title] AS [id] FROM [products])
// INSERT ...
dibi::insert('products', $record)->setFlag('IGNORE')->test();
// -> INSERT IGNORE INTO [products] ([title], [price], [active]) VALUES ('Super product', 318, 1)
// UPDATE ...
dibi::update('products', $record)->where('product_id = %d', $id)->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
// DELETE ...
dibi::delete('products')->where('product_id = %d', $id)->test();
// -> DELETE FROM [products] WHERE product_id = 10
// custom commands
dibi::command()->update('products')->where('product_id = %d', $id)->set($record)->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
dibi::command()->truncate('products')->test();
// -> TRUNCATE [products]
コード例 #7
0
ファイル: News.php プロジェクト: svoby/graweb2010
 public function insert(array $data)
 {
     return dibi::insert(':graweb:news', $data)->execute(dibi::IDENTIFIER);
 }
コード例 #8
0
ファイル: BaseModel.php プロジェクト: radypala/maga-website
 /**
  * basic insert
  *
  * @param array $data
  * @return int insertedId()
  */
 public function insert(array $data)
 {
     return dibi::insert(static::TABLE, $data)->execute(dibi::IDENTIFIER);
 }
コード例 #9
0
ファイル: UserModel.php プロジェクト: oaki/demoshop
 static function insert($values)
 {
     $user_value['name'] = @$values['name'];
     $user_value['surname'] = @$values['surname'];
     //		$user_value['email'] = $values['email'];
     $user_value['login'] = $values['login'];
     $user_value['activate'] = $values['activate'];
     $user_value['password'] = self::getHash($values['password']);
     $user_value['fbuid'] = @$values['fbuid'];
     $user_value['google_id'] = @$values['google_id'];
     $user_value['newsletter'] = @$values['newsletter'];
     $user_value['discount'] = @$values['discount'];
     unset($values['name'], $values['surname'], $values['login'], $values['password'], $values['activate'], $values['fbuid'], $values['newsletter'], $values['discount']);
     dibi::begin();
     dibi::insert(TABLE_USERS, $user_value)->execute();
     $values['user_id'] = dibi::insertId();
     dibi::insert(TABLE_USERS_INFO, $values)->execute();
     dibi::commit();
     return $values['user_id'];
 }
コード例 #10
0
ファイル: UsersModel.php プロジェクト: radypala/maga-website
 public function allowTemporaryLogin($userId, $email, $expirationTime = '+1 hour')
 {
     $token = Basic::randomizer(80);
     dibi::insert(self::TEMPORARY_LOGIN_TABLE, array('users_id' => $userId, 'email' => $email, 'token' => $token, 'expire' => dibi::datetime(strtotime($expirationTime))))->execute();
     return $token;
 }
コード例 #11
0
ファイル: Analytics.php プロジェクト: killsaw/Mescal
 public function logAccess()
 {
     return dibi::insert('analytics', array('ua' => $this->ua, 'ip' => $this->ip, 'sid' => $this->sid, 'referer' => $this->referer, 'page' => $this->page))->execute();
 }
コード例 #12
0
ファイル: player.class.php プロジェクト: roesel/lolcomp
 function addToDatabase($name, $value)
 {
     dibi::insert($name, $value)->on('DUPLICATE KEY UPDATE %a ', $value)->execute();
 }