本文整理汇总了PHP中JDatabaseDriver::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabaseDriver::escape方法的具体用法?PHP JDatabaseDriver::escape怎么用?PHP JDatabaseDriver::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JDatabaseDriver
的用法示例。
在下文中一共展示了JDatabaseDriver::escape方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Load categories.
*
* <code>
* $parentId = 2;
*
* $options = array(
* "offset" => 0,
* "limit" => 10,
* "order_by" => "a.name",
* "order_dir" => "DESC",
* );
*
* $categories = new Crowdfunding\Categories();
* $categories->setDb(\JFactory::getDbo());
*
* $categories->load($parentId);
* </code>
*
* @param null|int $parentId Parent ID or "root".
* @param array $options
*
* @throws \RuntimeException
*/
public function load($parentId = null, array $options = array())
{
$offset = array_key_exists('offset', $options) ? $options['offset'] : 0;
$limit = array_key_exists('limit', $options) ? $options['limit'] : 0;
$orderBy = array_key_exists('order_by', $options) ? $options['order_by'] : 'a.title';
$orderDir = array_key_exists('order_dir', $options) ? $options['order_dir'] : 'ASC';
$published = array_key_exists('state', $options) ? $options['state'] : null;
$orderDir = strtoupper($orderDir);
if (!in_array($orderDir, array('ASC', 'DESC'), true)) {
$orderDir = 'ASC';
}
$query = $this->db->getQuery(true);
$query->select('a.id, a.title, a.alias, a.description, a.params, ' . $query->concatenate(array('a.id', 'a.alias'), ':') . ' AS slug')->from($this->db->quoteName('#__categories', 'a'))->where('a.extension = ' . $this->db->quote($this->_extension));
if ($parentId !== null) {
$query->where('a.parent_id = ' . (int) $parentId);
}
// Filter by state.
if ($published === null) {
$query->where('a.published IN (0,1)');
} else {
$query->where('a.published = ' . (int) $published);
}
$query->order($this->db->escape($this->db->quoteName($orderBy) . ' ' . $orderDir));
$this->db->setQuery($query, (int) $offset, (int) $limit);
$this->data = (array) $this->db->loadAssocList('id');
}
示例2: load
/**
* Load images from database.
*
* <code>
* $projectId = 1;
*
* $options = array(
* "order_direction" => "DESC"
* );
*
* $images = new CrowdFundingImages(JFactory::getDbo());
* $images->load($projectId, $options);
*
* foreach($images as $image) {
* echo '<img src="'.$image["thumb"].'" />';
* echo '<img src="'.$image["image"].'" />';
* }
* </code>
*
* @param $id
* @param array $options
*
* @return array|mixed
*/
public function load($id, $options = array())
{
$query = $this->db->getQuery(true);
$query->select("a.id, a.image, a.thumb, a.project_id")->from($this->db->quoteName("#__crowdf_images", "a"))->where("a.project_id = " . (int) $id);
if (isset($options["order_direction"])) {
$orderDir = strcmp("DESC", $options["order_direction"]) ? "DESC" : "ASC";
$query->order("a.id " . $this->db->escape($orderDir));
}
$this->db->setQuery($query);
$results = $this->db->loadObjectList();
if (!$results) {
$results = array();
}
$this->items = $results;
}
示例3: loadByString
/**
* Load locations data by string from database.
*
* <code>
* $string = "Plovdiv";
*
* $locations = new CrowdFundingLocations(JFactory::getDbo());
* $locations->loadByString($string);
*
* foreach($locations as $location) {
* echo $location["id"];
* echo $location["name"];
* }
* </code>
*
* @param string $string
* @param int $mode Filter mode.
*
* Example:
*
* # Filter modes
* 0 = "string";
* 1 = "string%";
* 2 = "%string";
* 3 = "%string%";
*/
public function loadByString($string, $mode = 1)
{
$query = $this->db->getQuery(true);
switch ($mode) {
case 1:
// Beginning
$searchFilter = $this->db->escape($string, true) . '%';
break;
case 2:
// End
$searchFilter = '%' . $this->db->escape($string, true);
break;
case 3:
// Both
$searchFilter = '%' . $this->db->escape($string, true) . '%';
break;
default:
// NONE
$searchFilter = $this->db->escape($string, true);
break;
}
$search = $this->db->quote($searchFilter);
$caseWhen = ' CASE WHEN ';
$caseWhen .= $query->charLength('a.state_code', '!=', '0');
$caseWhen .= ' THEN ';
$caseWhen .= $query->concatenate(array('a.name', 'a.state_code', 'a.country_code'), ', ');
$caseWhen .= ' ELSE ';
$caseWhen .= $query->concatenate(array('a.name', 'a.country_code'), ', ');
$caseWhen .= ' END as name';
$query->select("a.id, " . $caseWhen)->from($this->db->quoteName("#__crowdf_locations", "a"))->where($this->db->quoteName("a.name") . " LIKE " . $search);
$this->db->setQuery($query, 0, 8);
$results = $this->db->loadAssocList();
if (!$results) {
$results = array();
}
$this->items = $results;
}
示例4: getEscaped
/**
* Get a database escaped string. For LIKE statemends: $db->Quote( $db->getEscaped( $text, true ) . '%', false )
*
* @param string $text
* @param boolean $escapeForLike : escape also % and _ wildcards for LIKE statements with % or _ in search strings (since CB 1.2.3)
* @return string
*/
public function getEscaped($text, $escapeForLike = false)
{
return $this->_db->escape($text, $escapeForLike);
}
示例5: escape
/**
* {@inheritdoc}
*/
public function escape($text)
{
return $this->_db->escape($text);
}
示例6: getEscaped
/**
* Get a database escaped string. For LIKE statemends: $db->Quote( $db->getEscaped( $text, true ) . '%', false )
*
* @param string $text
* @param boolean $escapeForLike : escape also % and _ wildcards for LIKE statements with % or _ in search strings (since CB 1.2.3)
* @return string
*/
function getEscaped($text, $escapeForLike = false)
{
if (checkJversion() >= 2) {
$result = $this->_db->escape($text);
} else {
$result = $this->_db->getEscaped($text);
}
if ($escapeForLike) {
$result = str_replace(array('%', '_'), array("\\%", "\\_"), $result);
}
return $result;
}
示例7: escape
/**
* {@inheritdoc}
*
* @codeCoverageIgnore
*/
public function escape($text, $extra = false)
{
return $this->_db->escape($text, $extra);
}