port updated sql library from satoko
This commit is contained in:
parent
7acd3999cb
commit
92835df662
1 changed files with 18 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/*
|
||||
* MySQL PDO based database engine
|
||||
* Sakura MySQL Database Engine
|
||||
*/
|
||||
|
||||
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 = '*') {
|
||||
|
||||
// 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(is_array($data)) {
|
||||
|
@ -184,7 +184,8 @@ class Database {
|
|||
|
||||
// Do more shit, don't feel like describing this so yeah
|
||||
foreach($data as $key => $value) {
|
||||
$prepare .= ($i ? ':' : '`') . $key . ($i ? '' : '`') . ($key == key(array_slice($data, -1, 1, true)) ? '' : ', ');
|
||||
if(strlen($value))
|
||||
$prepare .= ($i ? ':' : '`') . $key . ($i ? '' : '`') . ($key == key(array_slice($data, -1, 1, true)) ? '' : ', ');
|
||||
}
|
||||
|
||||
$prepare .= ')' . ($i ? ';' : ' VALUES ');
|
||||
|
@ -196,7 +197,8 @@ class Database {
|
|||
|
||||
// Bind those parameters
|
||||
foreach($data as $key => $value) {
|
||||
$query->bindParam(':'. $key, $value);
|
||||
if(strlen($value))
|
||||
$query->bindParam(':'. $key, $value);
|
||||
|
||||
// Unset variables to be safe
|
||||
unset($key);
|
||||
|
|
Reference in a new issue