本文整理匯總了PHP中DboSource::delete方法的典型用法代碼示例。如果您正苦於以下問題:PHP DboSource::delete方法的具體用法?PHP DboSource::delete怎麽用?PHP DboSource::delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DboSource
的用法示例。
在下文中一共展示了DboSource::delete方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testDeleteStatements
/**
* Test deletes with a mock.
*
* @return void
*/
public function testDeleteStatements() {
$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("DELETE FROM `$db`.`articles` WHERE 1 = 1");
$this->Dbo->expects($this->at(1))->method('execute')
->with("DELETE `Article` FROM `$db`.`articles` AS `Article` LEFT JOIN `$db`.`users` AS `User` " .
"ON (`Article`.`user_id` = `User`.`id`)" .
" WHERE 1 = 1");
$this->Dbo->expects($this->at(2))->method('execute')
->with("DELETE `Article` FROM `$db`.`articles` AS `Article` LEFT JOIN `$db`.`users` AS `User` " .
"ON (`Article`.`user_id` = `User`.`id`)" .
" WHERE 2=2");
$Article = new Article();
$this->Dbo->delete($Article);
$this->Dbo->delete($Article, true);
$this->Dbo->delete($Article, '2=2');
}
示例2: testDeleteNoComplexCondition
/**
* Test deletes without complex conditions.
*
* @return void
*/
public function testDeleteNoComplexCondition()
{
$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("DELETE `Article` FROM `{$db}`.`articles` AS `Article` WHERE `id` = 1");
$this->Dbo->expects($this->at(1))->method('execute')->with("DELETE `Article` FROM `{$db}`.`articles` AS `Article` WHERE NOT (`id` = 1)");
$Article = new Article();
$conditions = array('id' => 1);
$this->Dbo->delete($Article, $conditions);
$conditions = array('NOT' => array('id' => 1));
$this->Dbo->delete($Article, $conditions);
}
示例3: testDeleteStatements
/**
* Test deletes with a mock.
*
* @return void
*/
public function testDeleteStatements()
{
$this->loadFixtures('Boat', '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("DELETE FROM `{$db}`.`boats` WHERE 1 = 1");
$this->Dbo->expects($this->at(1))->method('execute')->with("DELETE `Boat` FROM `{$db}`.`boats` AS `Boat` LEFT JOIN `{$db}`.`users` AS `User` " . "ON (`Boat`.`user_id` = `User`.`id`)" . " WHERE 1 = 1");
$this->Dbo->expects($this->at(2))->method('execute')->with("DELETE `Boat` FROM `{$db}`.`boats` AS `Boat` LEFT JOIN `{$db}`.`users` AS `User` " . "ON (`Boat`.`user_id` = `User`.`id`)" . " WHERE 2=2");
$Boat = new Boat();
$this->Dbo->delete($Boat);
$this->Dbo->delete($Boat, true);
$this->Dbo->delete($Boat, '2=2');
}
示例4: delete
/**
408: * Generates and executes an SQL DELETE statement for given id/conditions on given model.
409: *
410: * @param Model $model
411: * @param mixed $conditions
412: * @return boolean Success
413: */
public function delete(Model $model, $conditions = null)
{
if (!$this->_useAlias) {
return parent::delete($model, $conditions);
}
$alias = $this->name($model->alias);
$table = $this->fullTableName($model);
$joins = implode(' ', $this->_getJoins($model));
if (empty($conditions)) {
$alias = $joins = false;
}
$complexConditions = false;
foreach ((array) $conditions as $key => $value) {
if (strpos($key, $model->alias) === false) {
$complexConditions = true;
break;
}
}
if (!$complexConditions) {
$joins = false;
}
$conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
if ($conditions === false) {
return false;
}
if ($this->execute($this->renderStatement('delete', compact('alias', 'table', 'joins', 'conditions'))) === false) {
$model->onError();
return false;
}
return true;
}
示例5: delete
/**
* Generates and executes an SQL DELETE statement for given id/conditions on given model.
*
* @param Model $model
* @param mixed $conditions
* @return boolean Success
*/
function delete(&$model, $conditions = null)
{
if (!$this->_useAlias) {
return parent::delete($model, $conditions);
}
$alias = $this->name($model->alias);
$table = $this->fullTableName($model);
$joins = implode(' ', $this->_getJoins($model));
if (empty($conditions)) {
$alias = $joins = false;
}
$conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
if ($conditions === false) {
return false;
}
if ($this->execute($this->renderStatement('delete', compact('alias', 'table', 'joins', 'conditions'))) === false) {
$model->onError();
return false;
}
return true;
}