update() public static méthode

public static update ( $table, $args ) : Dibi\Fluent
Résultat Dibi\Fluent
Exemple #1
0
 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;
     }
 }
Exemple #2
0
<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]
Exemple #3
0
 /**
  * basic update specified by $id
  *
  * @param int $id
  * @param array $data
  * @return DibiResult
  */
 public function update($id, array $data)
 {
     return dibi::update(static::TABLE, $data)->where('id = %i', $id)->execute();
 }
Exemple #4
0
 /**
  * activate user identified by token
  *
  * @param string $token
  * @return bool false => expired, true => approved
  * @throws TokenExpiredException
  */
 public static function activate($token)
 {
     $row = dibi::select("id, DATEDIFF(NOW(), registered) <= %i AS not_expired", self::EXPIRY_DAYS)->from(self::TABLE)->where("token = %s", $token)->fetch();
     // invalid token
     if (!$row) {
         throw new TokenExpiredException();
     } else {
         // all good => approve user
         if ($row->not_expired) {
             dibi::update(self::TABLE, array('approved' => 1))->where("id = %i", $row->id)->execute();
             // expired => delete him
         } else {
             dibi::delete(self::TABLE)->where("token = %s", $token)->execute();
             return false;
         }
     }
     return true;
 }
 public function findAllStrings()
 {
     $files = array();
     foreach (self::$dirs as $dir) {
         $path = realpath(APP_DIR . "\\{$dir}\\");
         $files = array_merge($files, $this->getFiles($path, array('php', 'phtml')));
     }
     //	z tohto suoru nechceme sosat
     $files = array_diff($files, array(__FILE__));
     $phrases = array();
     $patterns = array("#{_[\"\\']((?:\\\\?+.)*?)[\"\\']#s", "#\\s+(?:\\\$this->translate|_)\\([\\'|\"](.*)[\\'|\"]\\)#Us", "#flashMessage\\([\\'|\"](.*)[\\'|\"][,|\\)|(\\s+\\.\\s+)]#Us");
     foreach ($files as $file) {
         foreach ($patterns as $pattern) {
             preg_match_all($pattern, file_get_contents($file), $matches);
             foreach ($matches[1] as $val) {
                 //			    	$phrases[] = $val;
                 $phrases[$val] = substr($file, strlen(WWW_DIR) + 1);
             }
         }
     }
     $phrasesArray = $phrases;
     $phrases = array_unique(array_keys($phrases));
     if (!isset($this->dictionary)) {
         $this->buildDictionary();
     }
     $loadedPhrases = array_keys($this->dictionary);
     $allPhrases = array_unique(array_merge($phrases, $loadedPhrases));
     $oldOrForm = array_diff($loadedPhrases, $phrases);
     $newPhrases = array_diff($phrases, $loadedPhrases);
     //	    dump($phrasesArray);
     //	    dump($loadedPhrases);
     //	    dump($allPhrases);
     //	    dump($oldOrForm);
     //	    dump($newPhrases);
     //	    $oldOrForm
     //	    $newPhrases = array_diff_key(1)
     //	    dump($newPhrases);
     //	    dump();
     //	insert new phrases in 1 query
     if (count($newPhrases) > 0) {
         $files = $this->filterArray($newPhrases, $phrasesArray);
         //	    	dump($files);die();
         $data = array('msg_id' => array_keys($files), 'file' => array_values($files));
         dibi::query('INSERT INTO %n %m', self::TABLE, $data);
     }
     if (count($oldOrForm) > 0) {
         foreach ($oldOrForm as $phrase) {
             dibi::update(self::TABLE, array('oldOrForm' => 1))->where('msg_id = %s', $phrase)->execute();
         }
     }
     if ($this->debug) {
         //	  		dump($phrases);
         echo '<b>';
         echo count($allPhrases) . " phrases together<br>";
         echo count($files) . " files matched<br>";
         echo count($phrases) . " phrases found to be translated<br>";
         echo count($newPhrases) . " new phrases found:</b><br>" . join('<br>', $newPhrases);
         echo '<b>' . count($oldOrForm) . " phrases not found but exist in dictionary => possibly unused or from form:</b><br>" . join('<br>', $oldOrForm);
     }
     // aby sa refresol slovnik
     $cache = Environment::getCache('dictionary');
     unset($cache['data']);
     $this->buildDictionary();
 }