我有一个冗长的数组 $prices,其结构如下
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
)
我想将其放入已使用相应行创建的 mysql 表中。fund_id,class,currency,nav,nav_change,price_date
这是我将行插入多个数据库行的最新尝试
$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();
}
目前这正在返回一个致命错误:调用非对象上的成员函数 execute()。我不清楚mysqli方法的一些事情(显然),比如循环的去向以及这是否是访问数据的正确循环。
任何帮助都会很棒,谢谢。