本文整理匯總了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);
}