本文整理匯總了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'));
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}