I have a script that parses data from HTML tables and puts it into an array. Here's the sample output from the script:
Array
(
[] => Array
(
[] => Array
(
[] => Array
(
[] => Array
(
[] => 1
)
)
)
)
[Precinct Code] => Array
(
[Precinct] => Array
(
[Total Registered] => Array
(
[Total Voting] => Array
(
[Percent Voting] => 1
)
)
)
)
[004] => Array
(
[AWENDAW] => Array
(
[1299] => Array
(
[926] => Array
(
[71.285] => 1
)
)
)
)
)
I want to insert these arrays into a MySQL database, and I am using the following code:
$html = file_get_html('URL GOES HERE');
foreach($html->find('tr') as $row) {
$precinct = $row->find('td',0)->plaintext;
$precinctCode = $row->find('td',1)->plaintext;
$totalRegistered = $row->find('td',2)->plaintext;
$totalVoting = $row->find('td',3)->plaintext;
$percentVoting = $row->find('td',4)->plaintext;
$table[$precinctCode][$precinct][$totalRegistered][$totalVoting][$percentVoting] = true;
/* Dump each array into MySQL table */
$db = new PDO('mysql:host=localhost;dbname=MY_DATABASE_NAME', 'USERNAME', 'PASSWORD');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert = $db->prepare(
'INSERT INTO rsltStats (precinctCode , precinct, totalRegistered,
totalVoting, percentVoting ) VALUES (?, ?, ?, ?, ?)');
foreach($table as $values) {
$insert->execute($values);
}
}
However, it keeps throwing an error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'
I am fairly new to this so any help is appreciated.