Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easyCRUD function search miss bindings #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function write($message) {

if(is_dir($this->path)) {
if(!file_exists($log)) {
$fh = fopen($log, 'a+') or die("Fatal Error !");
$fh = fopen($log, 'w+') or die("Fatal Error !");
$logcontent = "Time : " . $date->format('H:i:s')."\r\n" . $message ."\r\n";
fwrite($fh, $logcontent);
fclose($fh);
Expand Down
34 changes: 17 additions & 17 deletions easyCRUD/easyCRUD.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
<?php
/**
* Easy Crud - This class kinda works like ORM. Just created for fun :)
* Easy Crud - This class kinda works like ORM. Just created for fun :)
*
* @author Author: Vivek Wicky Aswal. (https://twitter.com/#!/VivekWickyAswal)
* @version 0.1a
Expand All @@ -13,7 +13,7 @@ class Crud {
public $variables;

public function __construct($data = array()) {
$this->db = new DB();
$this->db = new DB();
$this->variables = $data;
}

Expand All @@ -27,7 +27,7 @@ public function __set($name,$value){
}

public function __get($name)
{
{
if(is_array($this->variables)) {
if(array_key_exists($name,$this->variables)) {
return $this->variables[$name];
Expand Down Expand Up @@ -55,7 +55,7 @@ public function save($id = "0") {
if(count($columns) > 1 ) {

$sql = "UPDATE " . $this->table . " SET " . $fieldsvals . " WHERE " . $this->pk . "= :" . $this->pk;
if($id === "0" && $this->variables[$this->pk] === "0") {
if($id === "0" && $this->variables[$this->pk] === "0") {
unset($this->variables[$this->pk]);
$sql = "UPDATE " . $this->table . " SET " . $fieldsvals;
}
Expand All @@ -66,7 +66,7 @@ public function save($id = "0") {
return null;
}

public function create() {
public function create() {
$bindings = $this->variables;

if(!empty($bindings)) {
Expand Down Expand Up @@ -95,8 +95,8 @@ public function find($id = "") {
$id = (empty($this->variables[$this->pk])) ? $id : $this->variables[$this->pk];

if(!empty($id)) {
$sql = "SELECT * FROM " . $this->table ." WHERE " . $this->pk . "= :" . $this->pk . " LIMIT 1";
$sql = "SELECT * FROM " . $this->table ." WHERE " . $this->pk . "= :" . $this->pk . " LIMIT 1";

$result = $this->db->row($sql, array($this->pk=>$id));
$this->variables = ($result != false) ? $result : null;
}
Expand Down Expand Up @@ -125,21 +125,21 @@ public function search($fields = array(), $sort = array()) {
}
$sql .= " WHERE " . implode(" AND ", $fieldsvals);
}

if (!empty($sort)) {
$sortvals = array();
foreach ($sort as $key => $value) {
$sortvals[] = $key . " " . $value;
}
$sql .= " ORDER BY " . implode(", ", $sortvals);
}
return $this->exec($sql);
return $this->exec($sql, $bindings);
}

public function all(){
return $this->db->query("SELECT * FROM " . $this->table);
}

public function min($field) {
if($field)
return $this->db->single("SELECT min(" . $field . ")" . " FROM " . $this->table);
Expand All @@ -163,20 +163,20 @@ public function sum($field) {
public function count($field) {
if($field)
return $this->db->single("SELECT count(" . $field . ")" . " FROM " . $this->table);
}
}


private function exec($sql, $array = null) {

if($array !== null) {
// Get result with the DB object
$result = $this->db->query($sql, $array);
$result = $this->db->query($sql, $array);
}
else {
// Get result with the DB object
$result = $this->db->query($sql, $this->variables);
$result = $this->db->query($sql, $this->variables);
}

// Empty bindings
$this->variables = array();

Expand Down