{{indexmenu_n>300}}
====== DB query using the funct. "_dbQuery" ======
FIXME Better TRANSLATE
Here's a small example of how the built-in function _dbQuery ** ** may be used in a script.
function _dbQuery($query='', $_queryMode='ASSOC') { ....... }
\\
**$_queryMode:**
* INSERT, DELETE, UPDATE
* ON_DUPLICATE //(INSERT ... ON DUPLICATE KEY)//
* ROW, ARRAY //(SELECT Queries) //
* COUNT //(Count)//
* COUNT_SHOW //(send SHOW query and count results)//
* ASSOC //(default)//
\\
===== Example: =====
**Adoption:** From a given table //(exemplarily "phpwcms_country")// data should be selected and displayed in a CP. \\
Of course the table can also be a self-created.
The script is stored in the folder /frontend_render/ . The data are here collected from the database, selected and placed into a usable format, here
db-ID | ' .LF.'ISO | ' .LF.'ISO3 | ' .LF.'ISONUM | ' .LF.'C-CODE | ' .LF.'C-NAME | ' .LF.'CONTINENT | ' .LF; $table .= '
'.$value['country_id']. ' | ' .LF.''.$value['country_iso']. ' | ' .LF.''.$value['country_iso3']. ' | ' .LF.''.$value['country_isonum']. ' | ' .LF.''.$value['country_continent_code'].' | ' .LF.''.$value['country_name']. ' | ' .LF.''.$value['country_continent'].' | ' .LF; $table .= '
'.LF;
$table .= ''.LF.''.LF;
$table .= LF.' db-ID '
.LF.' ISO '
.LF.' ISO3 '
.LF.' ISONUM '
.LF.' C-CODE '
.LF.' C-NAME '
.LF.' CONTINENT '
.LF;
$table .= ' '.LF;
foreach ($result as $value) {
$table .= ''.LF;
$table .= LF.''.$value['country_id']. ' '
.LF.''.$value['country_iso']. ' '
.LF.''.$value['country_iso3']. ' '
.LF.''.$value['country_isonum']. ' '
.LF.''.$value['country_continent_code'].' '
.LF.''.$value['country_name']. ' '
.LF.''.$value['country_continent'].' '
.LF;
$table .= ' '.LF;
}
$table .= ''.LF.''.LF;
}
}
if ($error_flag) $table = $error_text;
// --- Replace and insert into page
// $content["all"] = str_replace('{DB-QUERY:}',$table, $content["all"]); // Old version
$content["all"] = preg_replace('/\{DB-QUERY\:'.$input.'\}/', $table, $content["all"]);
}
?>
\\
Please pay attention to the inquiry of security after ## %%// --- catch the selector %%## \\
If the data comes from a user input, this data must be considered very low!!
**Links:**
* [[http://php.net/manual/de/function.preg-match.php|PHP preg_match]]
* [[http://www.php.net/manual/de/function.preg-replace.php|PHP preg_replace]]
* [[links/php/regular-expression]]
* [[http://php.net/manual/de/function.in-array.php|PHP in_array]]
\\