Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中带有关联数组的UPDATE语句返回通知_Php_Mysql - Fatal编程技术网

PHP中带有关联数组的UPDATE语句返回通知

PHP中带有关联数组的UPDATE语句返回通知,php,mysql,Php,Mysql,使用从Excel工作表加载到关联数组的数据更新表时遇到问题,以下是我的代码片段: foreach ($priceList as $sku => $price) { $stmt = $dbh->prepare("UPDATE product SET price = :price WHERE sku = :sku;"); $stmt->bindParam(':price', $price); $stmt->bindParam(':sku',

使用从Excel工作表加载到关联数组的数据更新表时遇到问题,以下是我的代码片段:

    foreach ($priceList as $sku => $price) {

    $stmt = $dbh->prepare("UPDATE product SET price = :price WHERE sku = :sku;");
    $stmt->bindParam(':price',  $price);
    $stmt->bindParam(':sku', $sku);
    $stmt->execute();
    echo 'Table has been updated...';

 }
执行后,表中的价格不会更新,我收到一条通知:“注意:数组到字符串的转换…”

我的阵列的var_转储:

array (size=1768)
      '32732eglo' => string '27.25' (length=5) 

我的表中的sku列是VARCHAR,price列是DECIMAL,我做错了什么?

从您的示例输出来看,您似乎有一个额外的数组层

array (size=1) 0 => 
         array (size=1768) 
               '32732eglo' => string '2...
所以使用

foreach ($priceList[0] as $sku => $price) {

所以我在数组中有一个数组,它是通过使用

$priceList[] = array_combine($skuArray,$pricesArray);
我通过在此行之前声明数组修复了它:

$priceList = array();
$priceList = array_combine($skuArray,$pricesArray);
或者简单地用一行:

$priceList = array_combine($skuArray,$pricesArray);

如您所知,您正在尝试使用类似字符串的数组$sku或$price是数组而不是字符串您的数组输出看起来好像您已经修改了它-您能给出实际输出的(第一部分)吗。@NigelRen数组(size=1)0=>array(size=1768)'32732eglo'=>string'27.25'(length=5)'97475eglo'=>string'57.51'(length=5)'97476eglo'=>string'0.00'(length=4)'9936EGLO '=字符串“0”(长度=4)'97 906EGLO '=字符串“329.17”(长度=6),我也会考虑上面的注释。