port updated sql library from satoko

This commit is contained in:
flash 2015-03-29 18:56:42 +02:00
parent 7acd3999cb
commit 92835df662

View file

@ -1,6 +1,6 @@
<?php <?php
/* /*
* MySQL PDO based database engine * Sakura MySQL Database Engine
*/ */
namespace Sakura; namespace Sakura;
@ -85,7 +85,7 @@ class Database {
public static function fetch($table, $fetchAll = true, $data = null, $order = null, $limit = null, $group = null, $distinct = false, $column = '*') { public static function fetch($table, $fetchAll = true, $data = null, $order = null, $limit = null, $group = null, $distinct = false, $column = '*') {
// Begin preparation of the statement // Begin preparation of the statement
$prepare = 'SELECT '. ($distinct ? 'DISTINCT ' : '') . $column .' FROM `' . Configuration::getLocalConfig('db', 'prefix') . $table . '`'; $prepare = 'SELECT '. ($distinct ? 'DISTINCT ' : '') . ($column == '*' ? '' : '`') . $column . ($column == '*' ? '' : '`') .' FROM `' . Configuration::getLocalConfig('db', 'prefix') . $table . '`';
// If $data is set and is an array continue // If $data is set and is an array continue
if(is_array($data)) { if(is_array($data)) {
@ -184,6 +184,7 @@ class Database {
// Do more shit, don't feel like describing this so yeah // Do more shit, don't feel like describing this so yeah
foreach($data as $key => $value) { foreach($data as $key => $value) {
if(strlen($value))
$prepare .= ($i ? ':' : '`') . $key . ($i ? '' : '`') . ($key == key(array_slice($data, -1, 1, true)) ? '' : ', '); $prepare .= ($i ? ':' : '`') . $key . ($i ? '' : '`') . ($key == key(array_slice($data, -1, 1, true)) ? '' : ', ');
} }
@ -196,6 +197,7 @@ class Database {
// Bind those parameters // Bind those parameters
foreach($data as $key => $value) { foreach($data as $key => $value) {
if(strlen($value))
$query->bindParam(':'. $key, $value); $query->bindParam(':'. $key, $value);
// Unset variables to be safe // Unset variables to be safe