首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在预置语句php中不同行插入多条记录

如何在预置语句php中不同行插入多条记录
EN

Stack Overflow用户
提问于 2018-07-04 23:12:26
回答 1查看 35关注 0票数 1

我在我的数据库中插入了一些带有值的字符串,让我们称之为table_1,现在我有了数组,我想将它们插入到我的SQL数据库的table_2中的单独行中。

$sql = 'INSERT INTO ' . $table_1 . '(shipping_fee, waybill_status, pickup_fee, ) 
        VALUES(:shipping_fee, :waybill_status, :pickup_fee)';

$stmt = $this->dbConn->prepare($sql);
$stmt->bindParam(':shipping_fee', $s_shipping_fee);
$stmt->bindParam(':waybill_status', $s_waybill_status);
$stmt->bindParam(':pickup_fee', $this->pickup_fee);

if($stmt->execute()){ //THIS INSERTED THE STRINGS PERFECTLY
    //NOW ALL VALUES TO BE INSERT INTO $sqal is an array

    $sqal = 'INSERT INTO ' . $table_2. '(id, waybill_number, client_id, item_name, item_weight, item_length, item_width, item_category, date_added) VALUES(null, :waybill_numberr, :client_idaa, :item_name, :item_weight, :item_length, :item_width, :item_category, :date_added)';

    $stmtaaa = $this->dbConn->prepare($sqal);
    $stmtaaa->bindParam(':item_name', $this->item_name); //ARRAY
    $stmtaaa->bindParam(':item_weight', $this->item_weight); //ARRAY
    $stmtaaa->bindParam(':item_length', $this->item_length); //ARRAY
    $stmtaaa->bindParam(':item_width', $this->item_width); //ARRAY
    $stmtaaa->bindParam(':item_category', $this->item_category); //ARRAY

    $stmtaaa->execute(); //HoW do I go about this.
} else {
    echo "Could not insert";
    exit();
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51176754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档