From fe32ffbdb28de5178857994bd4b430e06af95f84 Mon Sep 17 00:00:00 2001 From: Indieteq Date: Tue, 13 Nov 2012 22:20:24 +0100 Subject: fixed bug in easyCRUD --- easyCRUD/easyCRUD.class.php | 25 ++++++++++++++++--------- index.example.php | 6 +++--- settings.ini.php | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/easyCRUD/easyCRUD.class.php b/easyCRUD/easyCRUD.class.php index f369197..d6e6bff 100644 --- a/easyCRUD/easyCRUD.class.php +++ b/easyCRUD/easyCRUD.class.php @@ -12,16 +12,28 @@ class Crud { public $variables; + public function __construct($data = array()) { + $this->db = new DB(); + $this->variables = $data; + } + public function __set($name,$value){ - $this->variables[$name] = $value; + if(strtolower($name) === $this->pk) { + $this->variables[$this->pk] = $value; + } + else { + $this->variables[$name] = $value; + } } public function __get($name) { - if(array_key_exists($name,$this->variables)) { - return $this->variables[$name]; + if(is_array($this->variables)) { + if(array_key_exists($name,$this->variables)) { + return $this->variables[$name]; + } } - + $trace = debug_backtrace(); trigger_error( 'Undefined property via __get(): ' . $name . @@ -31,11 +43,6 @@ class Crud { return null; } - public function __construct($data = array()) { - $this->db = new DB(); - $this->variables = $data; - } - public function save($id = "0") { $this->variables[$this->pk] = (empty($this->variables[$this->pk])) ? $id : $this->variables[$this->pk]; diff --git a/index.example.php b/index.example.php index 71a78e0..783a08e 100644 --- a/index.example.php +++ b/index.example.php @@ -23,13 +23,13 @@ $persons_num = $db->query("SELECT * FROM Persons", null, PDO::FETCH_NUM); // Fetching single value - $firstname = $db->single("SELECT firstname FROM Persons WHERE Id = :id ", array('id' => '31' ) ); + $firstname = $db->single("SELECT firstname FROM Persons WHERE Id = :id ", array('id' => '3' ) ); // Single Row - $id_age = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"John")); + $id_age = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"Zoe")); // Single Row with numeric index - $id_age_num = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"John"),PDO::FETCH_NUM); + $id_age_num = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"Zoe"),PDO::FETCH_NUM); // Column, numeric index $ages = $db->column("SELECT age FROM Persons"); diff --git a/settings.ini.php b/settings.ini.php index d0472a7..35fd7a9 100644 --- a/settings.ini.php +++ b/settings.ini.php @@ -2,4 +2,4 @@ host = localhost user = root password = -dbname = ultim \ No newline at end of file +dbname = testdb \ No newline at end of file -- cgit v1.1