本文整理汇总了PHP中sql::q方法的典型用法代码示例。如果您正苦于以下问题:PHP sql::q方法的具体用法?PHP sql::q怎么用?PHP sql::q使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sql
的用法示例。
在下文中一共展示了sql::q方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_by_file_key
public function load_by_file_key($key)
{
$this->initialise();
/* Make sure name is set */
if (isset($key)) {
/* We need to check this table has a name field */
$fields = array_keys($this->_data);
if (in_array('file_key', $fields)) {
$sql = $this->data_source->sql;
$sql->select('*')->from($this->table_name);
/* Do we have a date_deleted field? */
if (in_array('date_deleted', $fields)) {
$name_condition = new sql_cond('file_key', sql::EQUALS, sql::q($key));
$date_deleted_condition = new sql_cond('date_deleted', sql::IS, new sql_null());
$sql->where(new sql_and($name_condition, $date_deleted_condition));
} else {
$sql->where(new sql_cond('file_key', sql::EQUALS, sql::q($key)));
}
/* Get the results */
$results = $sql->execute()->results();
if (count($results) == 1) {
$this->trigger(self::EVENT_ON_LOAD_BY_FILE_KEY);
return $this->load_by_data($results[0]);
} elseif (count($results) == 0) {
$this->error("Unable to find a record with key {$key}");
} elseif (count($results) > 1) {
$this->error(count($results) . " records found with key '{$key}'.");
}
} else {
$this->error('Unable to load by file_key, this table has no \'file_key\' field.');
}
} else {
$this->error('Unable to load by file_key, no file_key supplied');
}
return false;
}
示例2: load_by_image_id_and_actions
public function load_by_image_id_and_actions($image_id, $actions)
{
$this->initialise();
if (is_assoc($actions)) {
$sql = $this->data_source->sql;
$sql->select('*')->from($this->table_name);
$where = new sql_and(new sql_cond('image_id', sql::EQUALS, sql::q($image_id)), new sql_cond('date_deleted', sql::IS, new sql_null()));
$key_pairs = ['action_resized_to_height' => 'No', 'action_resized_to_width' => 'No', 'action_resized' => 'No', 'action_scaled' => 'No', 'action_gaussian_blur' => 'No', 'action_cropped' => 'No', 'action_cropped_from_center' => 'No', 'action_squared' => 'No'];
if (isset($actions['actions'])) {
$actions['actions'] = explode(",", $actions['actions']);
foreach ($actions['actions'] as $action) {
switch ($action) {
case "resize_to_height":
$key_pairs['action_resized_to_height'] = 'Yes';
$key_pairs['height'] = $actions['height'];
break;
case "resize_to_width":
$key_pairs['action_resized_to_width'] = 'Yes';
$key_pairs['width'] = $actions['width'];
break;
case "resize":
$key_pairs['action_resized'] = 'Yes';
$key_pairs['height'] = $actions['height'];
$key_pairs['width'] = $actions['width'];
break;
case "scale":
$key_pairs['action_scaled'] = 'Yes';
$key_pairs['scale'] = $actions['scale'];
break;
case "gaussian_blur":
$key_pairs['action_gaussian_blur'] = 'Yes';
break;
case "crop":
$key_pairs['action_cropped'] = 'Yes';
$key_pairs['height'] = $actions['height'];
$key_pairs['width'] = $actions['width'];
$key_pairs['start_x'] = $actions['x'];
$key_pairs['start_y'] = $actions['y'];
break;
case "crop_from_center":
$key_pairs['action_cropped_from_center'] = 'Yes';
$key_pairs['height'] = $actions['height'];
$key_pairs['width'] = $actions['width'];
break;
case "square":
$key_pairs['action_squared'] = 'Yes';
$key_pairs['size'] = $actions['size'];
break;
}
}
}
foreach ($key_pairs as $key => $value) {
if ($value) {
$where->add(new sql_cond($key, sql::EQUALS, sql::q($value)));
}
}
$sql->where($where);
$results = $sql->execute()->results();
if (count($results)) {
return $this->load_by_data($results[0]);
}
} else {
$this->error('No actions provided');
}
return false;
}