Problems with PHP function - PDO [closed]

0
Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\trofeugs2017\model\Model.php on line 81

How to fix the error?

Code:

<?php
class Model {

 protected $name_table;
 protected $fields;
 protected $id_row;
 public $con;


 public function __construct($name_table){
  $this->name_table = $name_table;
  $this->con = new PDO("mysql:host=localhost;dbname=trofeu2017", "root", ""); 
 }      
 function implodeFields($fields){
  return implode(', ', $fields);
 }
 function implodeKeys($fields){
  return implode(', ', array_keys($fields));
 }
 function implodeValues($fields){
  return "'" . implode("', '", array_values($fields)) . "'";
 }      
 public function updateTable(array $fields, $where){         
  if($where){
   $where = "WHERE {$where}";
  } else {
   $where = null;
  }
  foreach($fields as $key => $values){
   $campos[] = "'{$key}' = '{$values}'";
  }
  $fields = $this->implodeFields($campos);
  $sql = "UPDATE {$this->name_table} SET {$fields} {$where}";
  $update = $this->con->prepare($sql);
  if($update->execute()){
   return $update;
  } else {
   return false;
  }
 }
}
    
asked by anonymous 02.05.2017 / 23:06

1 answer

0

Apparently, you are passing an empty or wrong variable in the command prepare

Use the find command from your IDE and look for prepare and check the past variables.

    
03.05.2017 / 00:53