New mysql lib

master
vitalif 2010-12-14 00:21:45 +00:00
parent 894fcbd37a
commit ad448fcb9e
1 changed files with 11 additions and 7 deletions

View File

@ -77,7 +77,7 @@ function amysql_query($q)
if ($fp)
{
$t = microtime(true)-$start;
fwrite($fp, date("[Y-m-d H:i:s] ").intval($t/1000).".".($t%1000)." sec $q".(mysql_errno() ? ': ERROR! '.mysql_errno().': '.mysql_error() : '')."\n");
fwrite($fp, date("[Y-m-d H:i:s] ").sprintf("%.3f sec ", $t).$q.(mysql_errno() ? ': ERROR! '.mysql_errno().': '.mysql_error() : '')."\n");
fclose($fp);
}
return $result;
@ -163,6 +163,8 @@ function cmchainmatch($table, $parent_field, $start, $field, $value)
function mysql_where_builder($where)
{
if (!is_array($where))
return $where;
$wh = array();
foreach ($where as $k => $v)
{
@ -209,12 +211,15 @@ function mysql_select_builder($tables, $fields, $where, $options = NULL)
}
if (is_array($fields))
$fields = join(',', $fields);
if (is_array($where))
$where = mysql_where_builder($where);
$where = mysql_where_builder($where);
$tables = mysql_tables_builder($tables);
$sql = 'SELECT ';
if ($options['CALC_FOUND_ROWS'] || $options['SQL_CALC_FOUND_ROWS'])
$sql .= 'SQL_CALC_FOUND_ROWS ';
if ($options['NO_CACHE'] || $options['SQL_NO_CACHE'])
$sql .= 'SQL_NO_CACHE ';
elseif ($options['CACHE'] || $options['SQL_CACHE'])
$sql .= 'SQL_CACHE ';
$sql .= "$fields FROM $tables WHERE $where";
if ($g = $options['GROUP BY'])
{
@ -286,6 +291,7 @@ function mysql_tables_builder($tables)
$t .= " $join JOIN $table $k ON ".mysql_where_builder($v[2]);
else
$t = "$table $k";
continue;
}
else
$v = ($cfgTables[$v] ? '`'.$cfgTables[$v].'`' : $v) . ' ' . $k;
@ -367,8 +373,7 @@ function mysql_delete($tables, $where, $options = NULL)
{
global $mysql_primary_link;
$tables = mysql_tables_builder($tables);
if (is_array($where))
$where = mysql_where_builder($where);
$where = mysql_where_builder($where);
$sql = "DELETE FROM $tables WHERE $where";
if (is_array($options))
{
@ -444,8 +449,7 @@ function mysql_update($table, $rows, $where = NULL, $options = NULL)
else
$sql[] = $v;
}
if (is_array($where))
$where = mysql_where_builder($where);
$where = mysql_where_builder($where);
$sql = 'UPDATE ' . mysql_tables_builder($table) . ' SET ' . implode(', ', $sql) . ' WHERE ' . $where;
if (is_array($options))
{