summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIndieteq <admin@indieteq.com>2012-11-13 22:20:24 +0100
committerIndieteq <admin@indieteq.com>2012-11-13 22:23:36 +0100
commitfe32ffbdb28de5178857994bd4b430e06af95f84 (patch)
tree82c64729f347add74de4bb95e9a7fc255c74dbc9
parenta470727859a822c24754142544c6c520e34457bd (diff)
downloadphp-mysql-pdo-database-class-fe32ffbdb28de5178857994bd4b430e06af95f84.zip
php-mysql-pdo-database-class-fe32ffbdb28de5178857994bd4b430e06af95f84.tar.gz
php-mysql-pdo-database-class-fe32ffbdb28de5178857994bd4b430e06af95f84.tar.bz2
fixed bug in easyCRUD
-rw-r--r--easyCRUD/easyCRUD.class.php25
-rw-r--r--index.example.php6
-rw-r--r--settings.ini.php2
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