本文整理汇总了PHP中DBQuery::return_values_from_sql方法的典型用法代码示例。如果您正苦于以下问题:PHP DBQuery::return_values_from_sql方法的具体用法?PHP DBQuery::return_values_from_sql怎么用?PHP DBQuery::return_values_from_sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBQuery
的用法示例。
在下文中一共展示了DBQuery::return_values_from_sql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preg_split
$catd = preg_split('/\\|/', $category);
$parent = trim($catd[0]);
$catname = trim($catd[1]);
$cat = mysql_real_escape_string($catname);
$par = mysql_real_escape_string($parent);
$sql = "SELECT id FROM category WHERE category_title LIKE '{$cat}'; ";
$ids = DBQuery::return_values_from_sql($sql);
if (count($ids) == 1) {
$cat_id = $ids[0];
$sql = "INSERT INTO incident_category (category_id, incident_id) VALUES ('{$cat_id}', '{$id}'); ";
mysql_query($sql);
} elseif (count($ids) > 1) {
#ambiguous name - get parent's
$sql = "SELECT category.id FROM category WHERE category.category_title LIKE '{$cat}' ";
$sql .= "AND category.parent_id IN (SELECT par.id FROM category AS par WHERE par.category_title LIKE '{$par}');";
$pids = DBQuery::return_values_from_sql($sql);
if (count($ids) == 1) {
$cat_id = $pids[0];
$sql = "INSERT INTO incident_category (category_id, incident_id) VALUES ('{$cat_id}', '{$id}'); ";
mysql_query($sql);
}
} else {
/**
# This code will automatically add a new category with that name - commented out for now
$sql = "INSERT INTO category (category_title) VALUES ('$cat'); ";
$res = mysql_query($sql);
$cat_id = DBQuery::get_last_id();
$sql = "INSERT INTO incident_category (category_id, incident_id) VALUES ('$cat_id', '$id'); ";
*/
}
示例2: return_values
/**
* returns the list of values of $ret_field if a record with $field = $value exists in the given $table
* return an empty array otherwise
*/
public static function return_values($field, $value, $table, $ret_field)
{
$sql = "SELECT {$ret_field} FROM {$table} WHERE {$field} = '{$value}';";
return DBQuery::return_values_from_sql($sql);
}