title: Using php and mysql how to create a function to insert data in database
body: <p>i have to trying to creating a function to insert data in DB.</p>
  
  <pre><code>public function insert_db($db,$table,$data){
  
                  foreach ($data as $column =&gt; $value)
                  {
                      $sql = "INSERT INTO {$table} ({$column}) VALUES (:{$column});";
                      $stmt = $db-&gt;prepare($sql);
                      $stmt-&gt;execute(array(':'.$column =&gt; $value));
                  }
              }
  </code></pre>
  
  <p>I found this function here. But its not working, its say</p>
  
  <pre><code>Fatal error: Call to a member function execute() on boolean in ...
  </code></pre>
  
  <p>I'm using "new mysqli" , how can i solve this?</p>
  
  <p>thanks in advance. </p>