Hello,
I just recently started to switch to OOP in PHP, but am getting confused on almost every step :(
Right now, my current issue is i have this function:
I am using a another function (method) to grab all the attributes i have set for the database fields, but when i use the above code - it tells me the first and second values are not valid integers.
I know that maybe because its adding those '' (single quotes) there but i am not sure how i can make this function work without modifying anything outside of this function?
also, if possible could some one provide to me or point me to a place that explains about instantiate?
I am instantiating my array to objects from within the class but wanting to know if there is an easier method to do so my current code is below:
Thank you,
Regards
I just recently started to switch to OOP in PHP, but am getting confused on almost every step :(
Right now, my current issue is i have this function:
Code:
public function create() {
global $database;
$attributes = $this->sanitized_attributes();
$sql = "INSERT INTO ".self::$table_name." (";
$sql .= join(", ", array_keys($attributes));
$sql .= ") VALUES ('";
$sql .= join("', '", array_values($attributes));
$sql .= "')";
if($database->query($sql)) {
$this->id = $database->insert_id();
return true;
} else {
return false;
}
}
I know that maybe because its adding those '' (single quotes) there but i am not sure how i can make this function work without modifying anything outside of this function?
also, if possible could some one provide to me or point me to a place that explains about instantiate?
I am instantiating my array to objects from within the class but wanting to know if there is an easier method to do so my current code is below:
Code:
private static function instantiate($record) {
$object = new self;
foreach($record as $attribute=>$value){
if($object->has_attribute($attribute)) {
$object->$attribute = $value;
}
}
return $object;
}
Regards
Comment