Cleaning whitespace in database*.lib.php files.

skala
Ivan Tcholakov 15 years ago
parent 2a48943013
commit 17f0c58dbd
  1. 32
      main/inc/lib/database.lib.php
  2. 36
      main/inc/lib/database.mysqli.lib.php

@ -1343,18 +1343,18 @@ class Database {
*/ */
public static function select($columns = '*' , $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') { public static function select($columns = '*' , $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') {
$conditions = self::parse_conditions($conditions); $conditions = self::parse_conditions($conditions);
//@todo we could do a describe here to check the columns ... //@todo we could do a describe here to check the columns ...
$clean_columns = ''; $clean_columns = '';
if (is_array($columns)) { if (is_array($columns)) {
$clean_columns = implode(',', $columns); $clean_columns = implode(',', $columns);
} else { } else {
if ($columns == '*') { if ($columns == '*') {
$clean_columns = '*'; $clean_columns = '*';
} else { } else {
$clean_columns = (string)$columns; $clean_columns = (string)$columns;
} }
} }
@ -1370,11 +1370,11 @@ class Database {
if (isset($row['id'])) { if (isset($row['id'])) {
$array[$row['id']] = $row; $array[$row['id']] = $row;
} else { } else {
$array[] = $row; $array[] = $row;
} }
} }
} else { } else {
$array = self::fetch_array($result, $option); $array = self::fetch_array($result, $option);
} }
return $array; return $array;
} }
@ -1387,7 +1387,7 @@ class Database {
*/ */
public function parse_conditions($conditions) { public function parse_conditions($conditions) {
if (empty($conditions)) { if (empty($conditions)) {
return ''; return '';
} }
$return_value = ''; $return_value = '';
foreach ($conditions as $type_condition => $condition_data) { foreach ($conditions as $type_condition => $condition_data) {
@ -1426,9 +1426,9 @@ class Database {
if (!empty($order_array[1])) { if (!empty($order_array[1])) {
$order_array[1] = strtolower($order_array[1]); $order_array[1] = strtolower($order_array[1]);
$order = 'desc'; $order = 'desc';
if (in_array($order_array[1], array('desc', 'asc'))) { if (in_array($order_array[1], array('desc', 'asc'))) {
$order = $order_array[1]; $order = $order_array[1];
} }
} }
$return_value .= ' ORDER BY '.$order_array[0].' '.$order; $return_value .= ' ORDER BY '.$order_array[0].' '.$order;
} else { } else {
@ -1454,7 +1454,7 @@ class Database {
} }
private function parse_where_conditions($coditions){ private function parse_where_conditions($coditions){
return self::parse_conditions(array('where'=>$coditions)); return self::parse_conditions(array('where'=>$coditions));
} }
/** /**
@ -1484,9 +1484,9 @@ class Database {
$count = 1; $count = 1;
foreach ($attributes as $key=>$value) { foreach ($attributes as $key=>$value) {
$value = self::escape_string($value); $value = self::escape_string($value);
$update_sql .= "$key = '$value' "; $update_sql .= "$key = '$value' ";
if ($count < count($attributes)) { if ($count < count($attributes)) {
$update_sql.=', '; $update_sql.=', ';
} }
$count++; $count++;
} }

@ -691,10 +691,10 @@ class Database {
? new mysqli('p:'.$parameters['server'], $parameters['username'], $parameters['password']) ? new mysqli('p:'.$parameters['server'], $parameters['username'], $parameters['password'])
: new mysqli($parameters['server'], $parameters['username'], $parameters['password']); : new mysqli($parameters['server'], $parameters['username'], $parameters['password']);
if ($database_connection->connect_errno) { if ($database_connection->connect_errno) {
error_log($database_connection->connect_errno()); error_log($database_connection->connect_errno());
return false; return false;
} else { } else {
return true; return true;
} }
} }
@ -1346,18 +1346,18 @@ class Database {
*/ */
public static function select($columns = '*' , $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') { public static function select($columns = '*' , $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') {
$conditions = self::parse_conditions($conditions); $conditions = self::parse_conditions($conditions);
//@todo we could do a describe here to check the columns ... //@todo we could do a describe here to check the columns ...
$clean_columns = ''; $clean_columns = '';
if (is_array($columns)) { if (is_array($columns)) {
$clean_columns = implode(',', $columns); $clean_columns = implode(',', $columns);
} else { } else {
if ($columns == '*') { if ($columns == '*') {
$clean_columns = '*'; $clean_columns = '*';
} else { } else {
$clean_columns = (string)$columns; $clean_columns = (string)$columns;
} }
} }
@ -1373,11 +1373,11 @@ class Database {
if (isset($row['id'])) { if (isset($row['id'])) {
$array[$row['id']] = $row; $array[$row['id']] = $row;
} else { } else {
$array[] = $row; $array[] = $row;
} }
} }
} else { } else {
$array = self::fetch_array($result, $option); $array = self::fetch_array($result, $option);
} }
return $array; return $array;
} }
@ -1389,7 +1389,7 @@ class Database {
*/ */
private function parse_conditions($conditions) { private function parse_conditions($conditions) {
if (empty($conditions)) { if (empty($conditions)) {
return ''; return '';
} }
$return_value = ''; $return_value = '';
foreach ($conditions as $type_condition => $condition_data) { foreach ($conditions as $type_condition => $condition_data) {
@ -1426,9 +1426,9 @@ class Database {
if (!empty($order_array[1])) { if (!empty($order_array[1])) {
$order_array[1] = strtolower($order_array[1]); $order_array[1] = strtolower($order_array[1]);
$order = 'desc'; $order = 'desc';
if (in_array($order_array[1], array('desc', 'asc'))) { if (in_array($order_array[1], array('desc', 'asc'))) {
$order = $order_array[1]; $order = $order_array[1];
} }
} }
$return_value .= ' ORDER BY '.$order_array[0].' '.$order; $return_value .= ' ORDER BY '.$order_array[0].' '.$order;
} else { } else {
@ -1454,7 +1454,7 @@ class Database {
} }
private function parse_where_conditions($coditions){ private function parse_where_conditions($coditions){
return self::parse_conditions(array('where'=>$coditions)); return self::parse_conditions(array('where'=>$coditions));
} }
/** /**
@ -1484,9 +1484,9 @@ class Database {
$count = 1; $count = 1;
foreach ($attributes as $key=>$value) { foreach ($attributes as $key=>$value) {
$value = self::escape_string($value); $value = self::escape_string($value);
$update_sql .= "$key = '$value' "; $update_sql .= "$key = '$value' ";
if ($count < count($attributes)) { if ($count < count($attributes)) {
$update_sql.=', '; $update_sql.=', ';
} }
$count++; $count++;
} }

Loading…
Cancel
Save