
PDO.. Me hacer el insert en la db pero me tira un error..
Publicado por facundo (185 intervenciones) el 13/08/2017 00:42:34
Hola gente! estoy posteando ya que busque ese error por google pero no encuentro la solucion !!
el error que tira es este:
Notice: Indirect modification of overloaded property Product::$price has no effect in C:\xampp\htdocs\clase-02\index.php on line 43
y lo mismo para linea 44 y 45...
aca serian las lineas 9, 10 y 11
el codigo es este:
Index.php
Product.php:
Model.php:
Alguien tiene idea que es lo que causa ese error ? Desde ya muchas gracias por su ayuda, saludos!
el error que tira es este:
Notice: Indirect modification of overloaded property Product::$price has no effect in C:\xampp\htdocs\clase-02\index.php on line 43
y lo mismo para linea 44 y 45...
aca serian las lineas 9, 10 y 11
el codigo es este:
Index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$product->fillAttributes([
'price' => 453.12,
'stock' => '23',
'description' => 'sad asdasd asd as'
]);
try {
$sql = ("INSERT INTO productos(price,stock,description) VALUES(?,?,?)");
$stmt= $conn->prepare($sql);
$stmt->bindParam('1', $product->price, PDO::PARAM_INT ,4);
$stmt->bindParam('2', $product->stock, PDO::PARAM_INT ,3);
$stmt->bindParam('3', $product->description, PDO::PARAM_STR,50);
$stmt->execute();
} catch (PDOException $e){
echo 'No se pudo insertar el producto en la base de datos ' . $e->getMessage();
}
Product.php:
1
2
3
4
5
6
7
class Product extends Model
{
protected $fillable = [
'price','stock','description'
];
}
Model.php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Model
{
protected $attributes = [];
protected $fillable = [];
public function __set($prop, $value)
{
if (! in_array($prop, $this->fillable)) {
throw new Exception("This attribute '$prop' cannot be assigned", 1);
}
$this->attributes[$prop] = $value;
}
public function __get($prop)
{
if (! array_key_exists($prop, $this->attributes)) {
throw new Exception("The attribute {$prop} does not exists", 1);
}
return $this->attributes[$prop];
}
public function fillAttributes(array $data = [])
{
foreach ($data as $k => $v) {
$this->{$k} = $v;
}
}
}
Alguien tiene idea que es lo que causa ese error ? Desde ya muchas gracias por su ayuda, saludos!
Valora esta pregunta


0