本文整理汇总了PHP中Zend_Db::quote方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db::quote方法的具体用法?PHP Zend_Db::quote怎么用?PHP Zend_Db::quote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db
的用法示例。
在下文中一共展示了Zend_Db::quote方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: whereFieldValueIsNotIn
/**
* Allows one to quickly do a NOT IN MySQL query.
*
* @param string $field - The field to check against.
* @param array $values
*/
public function whereFieldValueIsNotIn($field, $values)
{
if (!count($values)) {
return $this;
}
// Escape the values.
$inString = '';
foreach ($values as $value) {
$inString .= $this->_zendDb->quote($value) . ',';
}
$inString = rtrim($inString, ',');
$this->where($this->_zendDb->quoteIdentifier($this->tableNameOrAlias() . '.' . $field) . ' NOT IN (' . $inString . ')');
return $this;
}
示例2: quoteInto
/**
* Quote Into
*
* This method overrides Zend_Db::where() so that we can have a little
* more flexibility. Specifically, there are 6 use cases for this method.
*
* $db->quoteInto('id = 5');
*
* A SQL string is passed. If this is all that is passed, we forward along
* to the Zend_DB_Select method.
*
* $db->quoteInto('firstname = ? OR lastname = ?', 'James');
*
* A SQL string is passed along with a single replacement value for all "?".
* In this case, we pass everything along as well since Zend_DB_Select handles this
* use case.
*
* $db->quoteInto('firstname = ? AND lastname = ?', 'Tom', 'Jones');
*
* A SQL string is passed along with a variable argument list, each representing
* a "?" placeholder value in the string.
*
* $db->quoteInto('firstname = :0 AND lastname = :1', 'Tom', 'Jones');
*
* A SQL string is passed along with a variable argument list, each representing
* a ":index" placeholder value in the string.
*
* $db->quoteInto('firstname = :0 AND lastname = :1', array('Tom', 'Jones'));
*
* A SQL string is passed along with an array where each value represents
* a ":index" placeholder value in the string.
*
* $db->quoteInto('firstname = :firstname AND lastname = :lastname', array('firstname' => 'Tom', 'lastname' => 'Jones'));
*
* A SQL string is passed along with an array where each value represents
* a ":key" placeholder value in the string.
*
* @param string $sql A SQL string
* @param string $args Variable list of arguments to replace into the string
* @return string The SQL string with escaped quotes
*/
public function quoteInto($sql)
{
$args = func_get_args();
if (count($args) < 2 || count($args) == 2 && !is_array($args[1])) {
// Nothing special happening here, pass it through to the default method.
// We do this instead of calling $this->_zendDb->quoteInto($sql, $args[1])
// because we're not sure if args[1] is there or not.
return call_user_func_array(array($this->_db, 'quoteInto'), $args);
}
// We are going to run our own replacement method.
$replacements = $args;
array_shift($replacements);
if (is_array($replacements[0])) {
// Here, we are passed an array of replacements with key/value combos
// that correspond to ":key" => "sqlValueToBeEscaped".
$replacements = $replacements[0];
}
// If we are using "?" placeholders, we need to change them over to indexed-placeholders.
$pieces = explode('?', $sql);
$sql = '';
foreach ($pieces as $i => $piece) {
$sql .= $piece;
if ($i == count($pieces) - 1) {
// We are on the last one, skip.
break;
}
$sql .= ':' . $i;
}
// At this point, we are using ":key" placeholders.
$pieces = preg_split('/:(\\w+)\\b/', $sql, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$sql = '';
foreach ($pieces as $key => $piece) {
if ($key % 2 == 0) {
// We are on a piece of the query.
$sql .= $piece;
} else {
// We are on a placeholder.
$sql .= $this->_db->quote($replacements[$piece]);
}
}
return $sql;
}
示例3: save
/**
* Saves the current attributes to the DB.
*/
public function save()
{
$this->beforeSave();
// Trims out non-fields and serializes data for DB entry.
$info = $this->info(true, true);
if (!$this->exists) {
$this->beforeCreate();
$this->_zendDb->insert($this->tableName(), $info);
if (!$this->id) {
$this->id = $this->_zendDb->lastInsertId();
}
$this->_afterCommand('insert');
$this->exists = true;
$this->afterCreate();
} else {
$this->_zendDb->update($this->tableName(), $info, 'id = ' . $this->_zendDb->quote($this->id));
$this->_afterCommand('update');
}
$this->afterSave();
$this->_lastSaveRow = $this->info();
}