insert data into a database with prepared statements pdo
<p>I changed the code so that i can insert directly into the database. Now I face an issue with line of code <code>$database-&gt;bindParam(':name', $name[0][$i]);</code>. Which gives me the error <code>Fatal error: Call to undefined method PDO::bindParam()</code> How can I fix this?</p>

<pre><code>$hostname = 'XXX';
$database = 'XXX';
$username = 'XXX';
$password = 'XXX';
$database = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);

function get_data($url)
{
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

$html = get_data($_GET['url']);
preg_match_all('/\&lt;font face\=\"Arial\"\&gt;\&lt;strong\&gt;(.*)\&lt;br\&gt;\&lt;font color/', $html, $name);
preg_match('/\&lt;strong\&gt;([A-Z\s0-9]+) BIRTHDAYS\&lt;\/strong\&gt;/', $html, $date);

for ($i=0, $n=count($name[1]); $i&lt;$n; ++$i) {       
        try {
            $insert = $database-&gt;prepare("INSERT INTO bday (name, birthdate) VALUES (:name, :date)");

            $database-&gt;bindParam(':name', $name[0][$i]);
            $database-&gt;bindParam(':date', $date[1]);

            $insert-&gt;execute();
        }

        catch (PDOException $e) {
            echo $e-&gt;getMessage();
        }
}
</code></pre>
