summaryrefslogtreecommitdiff
path: root/includes/mysqli_provider.php
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2014-12-07 17:34:29 +0100
committerPhilip Häusler <msquare@notrademark.de>2014-12-07 17:34:29 +0100
commitfa0e38ebff81a02f89bd4493627c49bbc48bc93b (patch)
treee29baae5ea6d4ca5888125063a0ea6da9a6c0ddf /includes/mysqli_provider.php
parent156db1eadd905c7ee4c7c37dc246c8c689ae2396 (diff)
add shift create model
Diffstat (limited to 'includes/mysqli_provider.php')
-rw-r--r--includes/mysqli_provider.php43
1 files changed, 25 insertions, 18 deletions
diff --git a/includes/mysqli_provider.php b/includes/mysqli_provider.php
index 9f901a40..9f4f1396 100644
--- a/includes/mysqli_provider.php
+++ b/includes/mysqli_provider.php
@@ -5,16 +5,23 @@
*/
function sql_close() {
global $sql_connection;
-
+
return $sql_connection->close();
}
/**
+ * Return NULL if given value is null.
+ */
+function sql_null($value = null) {
+ return $value == null ? 'NULL' : ("'" . sql_escape($value) . "'");
+}
+
+/**
* Start new transaction.
*/
function sql_transaction_start() {
global $sql_nested_transaction_level;
-
+
if ($sql_nested_transaction_level ++ == 0)
return sql_query("BEGIN");
else
@@ -26,7 +33,7 @@ function sql_transaction_start() {
*/
function sql_transaction_commit() {
global $sql_nested_transaction_level;
-
+
if (-- $sql_nested_transaction_level == 0)
return sql_query("COMMIT");
else
@@ -38,7 +45,7 @@ function sql_transaction_commit() {
*/
function sql_transaction_rollback() {
global $sql_nested_transaction_level;
-
+
if (-- $sql_nested_transaction_level == 0)
return sql_query("ROLLBACK");
else
@@ -48,17 +55,17 @@ function sql_transaction_rollback() {
/**
* Logs an sql error.
*
- * @param string $message
+ * @param string $message
* @return false
*/
function sql_error($message) {
sql_close();
-
+
$message = trim($message) . "\n";
$message .= debug_string_backtrace() . "\n";
-
+
error_log('mysql_provider error: ' . $message);
-
+
return false;
}
@@ -77,19 +84,19 @@ function sql_error($message) {
*/
function sql_connect($host, $user, $pass, $db) {
global $sql_connection;
-
+
$sql_connection = new mysqli($host, $user, $pass, $db);
if ($sql_connection->connect_errno)
return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error);
-
+
$result = $sql_connection->query("SET CHARACTER SET utf8;");
if (! $result)
return sql_error("Unable to set utf8 character set (" . $sql_connection->errno . ") " . $sql_connection->error);
-
+
$result = $sql_connection->set_charset('utf8');
if (! $result)
return sql_error("Unable to set utf8 names (" . $sql_connection->errno . ") " . $sql_connection->error);
-
+
return $sql_connection;
}
@@ -110,12 +117,12 @@ function sql_select_db($db_name) {
/**
* MySQL SELECT query
*
- * @param string $query
+ * @param string $query
* @return Result array or false on error
*/
function sql_select($query) {
global $sql_connection;
-
+
$result = $sql_connection->query($query);
if ($result) {
$data = array();
@@ -129,12 +136,12 @@ function sql_select($query) {
/**
* MySQL execute a query
*
- * @param string $query
+ * @param string $query
* @return mysqli_result boolean resource or false on error
*/
function sql_query($query) {
global $sql_connection;
-
+
$result = $sql_connection->query($query);
if ($result) {
return $result;
@@ -155,7 +162,7 @@ function sql_id() {
/**
* Escape a string for a sql query.
*
- * @param string $query
+ * @param string $query
* @return string
*/
function sql_escape($query) {
@@ -166,7 +173,7 @@ function sql_escape($query) {
/**
* Count query result lines.
*
- * @param string $query
+ * @param string $query
* @return int Count of result lines
*/
function sql_num_query($query) {