所以我有一些工作代码,但是我正在尝试重写它。有人告诉我PDO是从数组中获取参数的好方法。
try{
$INVENTORY_LOCATIONS = new \Picqer\Financials\Exact\ItemWarehouseStorageLocation($connection);
$INVENTORY_LOCATIONS_GET = $INVENTORY_LOCATIONS->filter('', '','ID, ItemCode, StorageLocationCode, ItemDescription, Stock');
foreach($INVENTORY_LOCATIONS_GET as $INVENTORY_LOCATIONS){
$inventorylocationID = $INVENTORY_LOCATIONS->ID;
$inventorylocationsItemCode = $INVENTORY_LOCATIONS->ItemCode;
$inventoryStorageLocationsCode = $INVENTORY_LOCATIONS->StorageLocationCode;
$inventorylocationsItemDescription = $INVENTORY_LOCATIONS->ItemDescription;
$inventorylocationsCurrenctStock = $INVENTORY_LOCATIONS->Stock;
$INVENTORY_LOCATIONS_SQL = "INSERT IGNORE INTO data_exact_inventory_locations (ID, Code, Opslaglocatie, Omschrijving, Op_voorraad)
VALUES ('$inventorylocationID','$inventorylocationsItemCode','$inventoryStorageLocationsCode','$inventorylocationsItemDescription','$inventorylocationsCurrenctStock')";
$INVENTORY_STMT = $pdoconn->prepare($INVENTORY_LOCATIONS_SQL);
$INVENTORY_STMT->execute();
}
} catch (Exception $e) {
echo 'Exception ->';
var_dump($e->getMessage());
}
重写代码:
try{
$INVENTORY_LOCATIONS_TRUNCATE = $conn->query("TRUNCATE `data_exact_inventory_locations`");
$INVENTORY_LOCATIONS = new \Picqer\Financials\Exact\ItemWarehouseStorageLocation($connection);
$INVENTORY_LOCATIONS_GET = $INVENTORY_LOCATIONS->filter('', '','ID, ItemCode, StorageLocationCode, ItemDescription, Stock');
$INVENTORY_SQL = "INSERT INTO data_exact_inventory_locations (ID, Code, Opslaglocatie, Omschrijving, Op_voorraad)
VALUES (:ID, :Code, :StorageLocationCode, :ItemDescription, :Stock)";
foreach($INVENTORY_LOCATIONS_GET as $INVENTORY_LOCATIONS){
$INVENTORY_STMT = $pdoconn->prepare($INVENTORY_SQL);
$INVENTORY_STMT->execute(array($INVENTORY_LOCATIONS));
}
} catch (Exception $e) {
echo 'Exception ->';
var_dump($e->getMessage());
}
我不知道重写的代码出了什么问题,但我不断收到错误消息
Picqer \ Financials \ Exact \ ItemWarehouseStorageLocation类的对象无法在第99行上转换为字符串