mysql fun times

This commit is contained in:
Udo Schroeter 2021-11-27 15:02:21 +01:00
parent 19ebedc2fe
commit e6524f5a2a
3 changed files with 13 additions and 50 deletions

Binary file not shown.

View File

@ -67,57 +67,18 @@ string MySQL::escape(string raw, char quote_char)
return(result);
}
/* static function ParseQueryParams($query, $parameters = null)
{
if ($parameters != null)
{
$pctr = 0;
$result = '';
for($a = 0; $a < strlen($query); $a++)
{
$chr = substr($query, $a, 1);
if ($chr == '?')
{
$result .= '"'.DB::Safe($parameters[$pctr]).'"';
$pctr++;
}
else if ($chr == '&')
{
$result .= ''.intval($parameters[$pctr]).'';
$pctr++;
}
else if ($chr == ':')
{
$paramName = '';
$a += 1;
$pFormat = 'string';
if($query[$a] == ':')
{
$pFormat = 'number';
$a += 1;
}
while(!ctype_space($chr = substr($query, $a, 1)) && $a < strlen($query))
{
$paramName .= $chr;
$a += 1;
}
if($pFormat == 'number')
$result .= ' '.($parameters[$paramName]+0).' ';
else
$result .= ' "'.DB::Safe($parameters[$paramName]).'" ';
}
else
$result .= $chr;
}
}
else
$result = $query;
$q = str_replace('#', cfg('db/prefix'), $result);
self::$lastQuery = $q;
return($q);
}*/
bool MySQL::query(string query)
{
auto res = mysql_query((MYSQL*)connection, query.c_str());
return(true);
}
string MySQL::parse_query_parameters(string query, StringMap map)
bool MySQL::query(string query, StringMap params)
{
return(query(parse_query_parameters(query, params)));
}
string MySQL::parse_query_parameters(string query, StringMap map)
{
string result;
query.append(1, ' ');

View File

@ -8,5 +8,7 @@ struct MySQL {
string error();
string escape(string raw, char quote_char = '\'');
string parse_query_parameters(string query, StringMap m);
bool query(string query);
bool query(string query, StringMap params);
};