diff options
Diffstat (limited to 'lib/sql.php')
-rw-r--r-- | lib/sql.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/sql.php b/lib/sql.php new file mode 100644 index 0000000..9f65568 --- /dev/null +++ b/lib/sql.php @@ -0,0 +1,51 @@ +<?php + +require("conf/sql.php"); + +$sql_queries = 0; +$sql_connected = false; + +function sql_connect() { + global $sql_server, $sql_user, $sql_password, $sql_database, $sql_connected; + if ($sql_connected == true) return; + if (!@mysql_connect($sql_server, $sql_user, $sql_password)) { + $title = "Cannot connect to SQL server"; + $error = "An error has occurred with the SQL server !"; + require("tpl/general/empty.php"); + } + mysql_select_db($sql_database); + mysql_query("SET NAMES 'utf8'"); + $sql_connected = true; +} + +function sql($r) { + global $sql_queries, $sql_connected; + if ($sql_connected != true) sql_connect(); + $sql_queries++; + if ($a = mysql_query($r)) { + return $a; + } else { + $title = "SQL error."; + $request = $r; + $sql_error = mysql_error(); + require("tpl/general/sqlerror.php"); + } +} + +function esca($v) { + if (get_magic_quotes_gpc()) { + return stripslashes($v); + } else { + return $v; + } +} +function escs($v) { + sql_connect(); + return mysql_escape_string($v); +} +function esc($v) { + return escs(esca($v)); +} + + + |