I have a lengthy array $prices that is structured like this
Array
(
[Fund] => BGEF
[Class] => G
[Currency] => CAD
[NAV] => 8.6442
[NavChange] => 0.0431
[PriceDate] => 2013-05-01
)
Array
(
[Fund] => BGOF
[Class] => G
[Currency] => EUR
[NAV] => 12.1503
[NavChange] => 0.0226
[PriceDate] => 2013-05-01
)
Array
(
[Fund] => BIEF
[Class] => G
[Currency] => USD
[NAV] => 9.6914
[NavChange] => 0.0635
[PriceDate] => 2013-05-01
)
I want to put it into a mysql table that has been created with the corresponding rows. fund_id,class,currency,nav,nav_change,price_date
here is my latest attempt to insert the rows into multiple db rows
$mysqli = new mysqli( "localhost", "user", "pw","db" );
if( $mysqli->connect_errno ){
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$mysqli->select_db("db");
foreach($prices as $rows){
$sql = " INSERT INTO price_data( price_date,fund_id,currency_id,class_id,nav,nav_change )
VALUES ( $rows[PriceDate] , $rows[Fund] , $rows[currency] , $rows[Class] , $rows[NAV] , $rows[NavChange] ) " ;
$stmt = $mysqli->prepare($sql);
$stmt->execute();
}
Currently this is returning a Fatal error: Call to a member function execute() on a non-object. I'm not clear on a few things (obviously) with the mysqli approach, like where the loop goes and if this is the right kind of loop to access the data.
Any help would be great, thanks.