當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DboSource::update方法代碼示例

本文整理匯總了PHP中DboSource::update方法的典型用法代碼示例。如果您正苦於以下問題:PHP DboSource::update方法的具體用法?PHP DboSource::update怎麽用?PHP DboSource::update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DboSource的用法示例。


在下文中一共展示了DboSource::update方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testUpdateStatements

/**
 * testStatements method
 *
 * @return void
 */
	public function testUpdateStatements() {
		$this->loadFixtures('Article', 'User');
		$test = ConnectionManager::getDatasource('test');
		$db = $test->config['database'];

		$this->Dbo = $this->getMock('Mysql', array('execute'), array($test->config));

		$this->Dbo->expects($this->at(0))->method('execute')
			->with("UPDATE `$db`.`articles` SET `field1` = 'value1'  WHERE 1 = 1");

		$this->Dbo->expects($this->at(1))->method('execute')
			->with("UPDATE `$db`.`articles` AS `Article` LEFT JOIN `$db`.`users` AS `User` ON " .
				"(`Article`.`user_id` = `User`.`id`)" .
				" SET `Article`.`field1` = 2  WHERE 2=2");

		$this->Dbo->expects($this->at(2))->method('execute')
			->with("UPDATE `$db`.`articles` AS `Article` LEFT JOIN `$db`.`users` AS `User` ON " .
				"(`Article`.`user_id` = `User`.`id`)" .
				" SET `Article`.`field1` = 'value'  WHERE `index` = 'val'");

		$Article = new Article();

		$this->Dbo->update($Article, array('field1'), array('value1'));
		$this->Dbo->update($Article, array('field1'), array('2'), '2=2');
		$this->Dbo->update($Article, array('field1'), array("'value'"), array('index' => 'val'));
	}
開發者ID:hungnt88,項目名稱:5stars-1,代碼行數:31,代碼來源:MysqlTest.php

示例2: update

 /**
  * Generates and executes an SQL UPDATE statement for given model, fields, and values.
  *
  * @param Model $model
  * @param array $fields
  * @param array $values
  * @param mixed $conditions
  * @return array
  */
 function update(&$model, $fields = array(), $values = null, $conditions = null)
 {
     if (!$this->_useAlias) {
         return parent::update($model, $fields, $values, $conditions);
     }
     if ($values == null) {
         $combined = $fields;
     } else {
         $combined = array_combine($fields, $values);
     }
     $alias = $joins = false;
     $fields = $this->_prepareUpdateFields($model, $combined, empty($conditions), !empty($conditions));
     $fields = join(', ', $fields);
     $table = $this->fullTableName($model);
     if (!empty($conditions)) {
         $alias = $this->name($model->alias);
         if ($model->name == $model->alias) {
             $joins = implode(' ', $this->_getJoins($model));
         }
     }
     $conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
     if ($conditions === false) {
         return false;
     }
     if (!$this->execute($this->renderStatement('update', compact('table', 'alias', 'joins', 'fields', 'conditions')))) {
         $model->onError();
         return false;
     }
     return true;
 }
開發者ID:afzet,項目名稱:connectivo-crm,代碼行數:39,代碼來源:dbo_mysql.php

示例3: update

 /**
  * Generates and executes an SQL UPDATE statement for given model, fields, and values.
  *
  * @param Model $model The model instance to update.
  * @param array $fields The fields to update.
  * @param array $values The values to set columns to.
  * @param mixed $conditions array of conditions to use.
  * @return array
  */
 public function update(Model $model, $fields = array(), $values = null, $conditions = null)
 {
     if (empty($values) && !empty($fields)) {
         foreach ($fields as $field => $value) {
             if (strpos($field, $model->alias . '.') !== false) {
                 unset($fields[$field]);
                 $field = str_replace($model->alias . '.', "", $field);
                 $field = str_replace($model->alias . '.', "", $field);
                 $fields[$field] = $value;
             }
         }
     }
     return parent::update($model, $fields, $values, $conditions);
 }
開發者ID:lakshmanpalitha,項目名稱:cakeproject,代碼行數:23,代碼來源:Sqlite.php

示例4: testUpdateAllSyntax

 /**
  * testUpdateAllSyntax method
  *
  * @return void
  */
 public function testUpdateAllSyntax()
 {
     $fields = array('SqlserverTestModel.client_id' => '[SqlserverTestModel].[client_id] + 1');
     $conditions = array('SqlserverTestModel.updated <' => date('2009-01-01 00:00:00'));
     $this->db->update($this->model, $fields, null, $conditions);
     $result = $this->db->getLastQuery();
     $this->assertNotRegExp('/SqlserverTestModel/', $result);
     $this->assertRegExp('/^UPDATE \\[sqlserver_test_models\\]/', $result);
     $this->assertRegExp('/SET \\[client_id\\] = \\[client_id\\] \\+ 1/', $result);
 }
開發者ID:netun0,項目名稱:cakephp-social-harvester,代碼行數:15,代碼來源:SqlserverTest.php

示例5: update

 /**
  * Generates and executes an SQL UPDATE statement for given model, fields, and values.
  * Removes Identity (primary key) column from update data before returning to parent.
  *
  * @param Model $model
  * @param array $fields
  * @param array $values
  * @param mixed $conditions
  * @return array
  */
 function update(&$model, $fields = array(), $values = null, $conditions = null)
 {
     if (!empty($values)) {
         $fields = array_combine($fields, $values);
     }
     if (isset($fields[$model->primaryKey])) {
         unset($fields[$model->primaryKey]);
     }
     if (empty($fields)) {
         return true;
     }
     return parent::update($model, array_keys($fields), array_values($fields), $conditions);
 }
開發者ID:xplico,項目名稱:xplico,代碼行數:23,代碼來源:dbo_sqlsrv.php

示例6: update

 /**
  * Removes Identity (primary key) column from update data before returning to parent
  *
  * @param Model $model
  * @param array $fields
  * @param array $values
  * @return array
  */
 function update(&$model, $fields = array(), $values = array())
 {
     foreach ($fields as $i => $field) {
         if ($field == $model->primaryKey) {
             unset($fields[$i]);
             unset($values[$i]);
             break;
         }
     }
     return parent::update($model, $fields, $values);
 }
開發者ID:rhencke,項目名稱:mozilla-cvs-history,代碼行數:19,代碼來源:dbo_firebird.php

示例7: testUpdateAllSyntax

 /**
  * testUpdateAllSyntax method
  *
  * @return void
  * @access public
  */
 function testUpdateAllSyntax()
 {
     $fields = array('MssqlTestModel.client_id' => '[MssqlTestModel].[client_id] + 1');
     $conditions = array('MssqlTestModel.updated <' => date('2009-01-01 00:00:00'));
     $this->db->update($this->model, $fields, null, $conditions);
     $result = $this->db->getLastQuery();
     $this->assertNoPattern('/MssqlTestModel/', $result);
     $this->assertPattern('/^UPDATE \\[mssql_test_models\\]/', $result);
     $this->assertPattern('/SET \\[client_id\\] = \\[client_id\\] \\+ 1/', $result);
 }
開發者ID:kevinmel2000,項目名稱:Study-Buddy---CakePHP-Quiz-System,代碼行數:16,代碼來源:dbo_mssql.test.php

示例8: update

 /**
  * Generates and executes an SQL UPDATE statement for given model, fields, and values.
  *
  * @param Model $model      The model to update.
  * @param array $fields     The fields to update.
  * @param array $values     The values to set.
  * @param mixed $conditions The conditions to use.
  *
  * @return array
  */
 public function update(Model $model, $fields = array(), $values = NULL, $conditions = NULL)
 {
     if (!$this->_useAlias) {
         return parent::update($model, $fields, $values, $conditions);
     }
     if (!$values) {
         $combined = $fields;
     } else {
         $combined = array_combine($fields, $values);
     }
     $alias = $joins = FALSE;
     $fields = $this->_prepareUpdateFields($model, $combined, empty($conditions), !empty($conditions));
     $fields = implode(', ', $fields);
     $table = $this->fullTableName($model);
     if (!empty($conditions)) {
         $alias = $this->name($model->alias);
         if ($model->name === $model->alias) {
             $joins = implode(' ', $this->_getJoins($model));
         }
     }
     $conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), TRUE, TRUE, $model);
     if ($conditions === FALSE) {
         return FALSE;
     }
     if (!$this->execute($this->renderStatement('update', compact('table', 'alias', 'joins', 'fields', 'conditions')))) {
         $model->onError();
         return FALSE;
     }
     return TRUE;
 }
開發者ID:mrbadao,項目名稱:api-official,代碼行數:40,代碼來源:Mysql.php

示例9: update

 /**
  * Generates and executes an SQL UPDATE statement for given model, fields, and values.
  * Removes Identity (primary key) column from update data before returning to parent.
  *
  * @param Model $model      The model to update.
  * @param array $fields     The fields to set.
  * @param array $values     The values to set.
  * @param mixed $conditions The conditions to use.
  *
  * @return array
  */
 public function update(Model $model, $fields = array(), $values = NULL, $conditions = NULL)
 {
     if (!empty($values)) {
         $fields = array_combine($fields, $values);
     }
     if (isset($fields[$model->primaryKey])) {
         unset($fields[$model->primaryKey]);
     }
     if (empty($fields)) {
         return TRUE;
     }
     return parent::update($model, array_keys($fields), array_values($fields), $conditions);
 }
開發者ID:mrbadao,項目名稱:api-official,代碼行數:24,代碼來源:Sqlserver.php


注:本文中的DboSource::update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。