本文整理汇总了PHP中Zend\Db\Sql\Insert::prepareStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP Insert::prepareStatement方法的具体用法?PHP Insert::prepareStatement怎么用?PHP Insert::prepareStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Db\Sql\Insert
的用法示例。
在下文中一共展示了Insert::prepareStatement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPrepareStatement
/**
* @covers Zend\Db\Sql\Insert::prepareStatement
*/
public function testPrepareStatement()
{
$mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
$mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
$mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMock('Zend\\Db\\Adapter\\Adapter', null, array($mockDriver));
$mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
$pContainer = new \Zend\Db\Adapter\ParameterContainer(array());
$mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
$mockStatement->expects($this->at(1))->method('setSql')->with($this->equalTo('INSERT INTO "foo" ("bar", "boo") VALUES (?, NOW())'));
$this->insert->into('foo')->values(array('bar' => 'baz', 'boo' => new Expression('NOW()')));
$this->insert->prepareStatement($mockAdapter, $mockStatement);
// with TableIdentifier
$this->insert = new Insert();
$mockDriver = $this->getMock('Zend\\Db\\Adapter\\Driver\\DriverInterface');
$mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
$mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMock('Zend\\Db\\Adapter\\Adapter', null, array($mockDriver));
$mockStatement = $this->getMock('Zend\\Db\\Adapter\\Driver\\StatementInterface');
$pContainer = new \Zend\Db\Adapter\ParameterContainer(array());
$mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
$mockStatement->expects($this->at(1))->method('setSql')->with($this->equalTo('INSERT INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())'));
$this->insert->into(new TableIdentifier('foo', 'sch'))->values(array('bar' => 'baz', 'boo' => new Expression('NOW()')));
$this->insert->prepareStatement($mockAdapter, $mockStatement);
}
示例2: prepareStatement
public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
{
/* init */
$this->hasAutoincrement = false;
/* parent prep */
$result = parent::prepareStatement($adapter, $statementContainer);
/* oci8 with autoincrement */
if ($statementContainer instanceof \Zend\Db\Adapter\Driver\Oci8\Statement && $this->autoincrement !== null) {
/* get sequence */
if ($this->sequence === null) {
$this->sequence = 'SEQ_' . $this->table;
}
/* replace ai field with sequence & move ai field binding to the end with returning */
$count = 0;
$sql = preg_replace('/:' . $this->autoincrement . '\\s*/', $this->sequence . '.NEXTVAL', $statementContainer->getSql(), 1, $count) . ' RETURNING "' . $this->autoincrement . '" INTO :' . $this->autoincrement;
/* anything replaced? */
if ($count > 0) {
/* prep statement to prep resource */
$statementContainer->setSql($sql);
$statementContainer->prepare();
/* unset ai field */
$statementContainer->getParameterContainer()->offsetUnset($this->autoincrement);
/* get ai field position on values */
$position = array_search($this->autoincrement, $this->columns);
$this->values[$position] = 0;
$this->hasAutoincrement = true;
oci_bind_by_name($statementContainer->getResource(), $this->autoincrement, $this->values[$position], -1, SQLT_INT);
}
}
//oci8 AI
return $result;
}
示例3: prepareStatement
/**
* Prepare statement
*
* @param AdapterInterface $adapter
* @param StatementContainerInterface $statementContainer
* @return void
*/
public function prepareStatement(AdapterInterface $adapter, StatementContainerInterface $statementContainer)
{
parent::prepareStatement($adapter, $statementContainer);
$sql = $statementContainer->getSql();
$statementContainer->setSql($sql . "ON DUPLICATE KEY UPDATE " . implode(",", array_map(array($this, "mapValue"), $this->columns)));
}