Skip to content

Commit fe32ffb

Browse files
author
Indieteq
committed
fixed bug in easyCRUD
1 parent a470727 commit fe32ffb

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

easyCRUD/easyCRUD.class.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,28 @@ class Crud {
1212

1313
public $variables;
1414

15+
public function __construct($data = array()) {
16+
$this->db = new DB();
17+
$this->variables = $data;
18+
}
19+
1520
public function __set($name,$value){
16-
$this->variables[$name] = $value;
21+
if(strtolower($name) === $this->pk) {
22+
$this->variables[$this->pk] = $value;
23+
}
24+
else {
25+
$this->variables[$name] = $value;
26+
}
1727
}
1828

1929
public function __get($name)
2030
{
21-
if(array_key_exists($name,$this->variables)) {
22-
return $this->variables[$name];
31+
if(is_array($this->variables)) {
32+
if(array_key_exists($name,$this->variables)) {
33+
return $this->variables[$name];
34+
}
2335
}
24-
36+
2537
$trace = debug_backtrace();
2638
trigger_error(
2739
'Undefined property via __get(): ' . $name .
@@ -31,11 +43,6 @@ public function __get($name)
3143
return null;
3244
}
3345

34-
public function __construct($data = array()) {
35-
$this->db = new DB();
36-
$this->variables = $data;
37-
}
38-
3946
public function save($id = "0") {
4047
$this->variables[$this->pk] = (empty($this->variables[$this->pk])) ? $id : $this->variables[$this->pk];
4148

index.example.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
$persons_num = $db->query("SELECT * FROM Persons", null, PDO::FETCH_NUM);
2424

2525
// Fetching single value
26-
$firstname = $db->single("SELECT firstname FROM Persons WHERE Id = :id ", array('id' => '31' ) );
26+
$firstname = $db->single("SELECT firstname FROM Persons WHERE Id = :id ", array('id' => '3' ) );
2727

2828
// Single Row
29-
$id_age = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"John"));
29+
$id_age = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"Zoe"));
3030

3131
// Single Row with numeric index
32-
$id_age_num = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"John"),PDO::FETCH_NUM);
32+
$id_age_num = $db->row("SELECT Id, Age FROM Persons WHERE firstname = :f", array("f"=>"Zoe"),PDO::FETCH_NUM);
3333

3434
// Column, numeric index
3535
$ages = $db->column("SELECT age FROM Persons");

settings.ini.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
host = localhost
33
user = root
44
password =
5-
dbname = ultim
5+
dbname = testdb

0 commit comments

Comments
 (0)