Executing Multiple Queries Using PDO

后端 未结 3 1553
既然无缘
既然无缘 2021-01-28 04:13

I am trying to execute the following query using a PDO Prepared Statement, but when I call $query->fetch(); it throws an exception SQLSTATE[HY000]: General

3条回答
  •  一个人的身影
    2021-01-28 05:01

    You don't need a multiple statement.

    So just run your queries one by one

    $db = new Database(); //Create a new object of type Database establishing a connection to the MySQL database
    $query = $db->pdo->prepare("INSERT INTO `orders` (`order_type`, `item`, `amount`, `price`, `price_btc`, `status`, `timestamp`, `placed_by`, `secret`, `first_name`, `last_name`, `address_1`, `address_2`, `city`, `zip_code`, `country`, `state`, `phone_number`)
                             VALUES(:order_type, :item, :amount, :price, :price_btc, :status, :timestamp, :placed_by, :secret, :first_name, :last_name, :address_1, :address_2, :city, :zip_code, :country, :state, :phone_number)"
    ); //Prepare the first query
    
    /*HERE IS SOME CODE TO BIND PLACEHOLDERS TO SOME VALUES*/
    
    $query->execute();
    
    $order = $db->pdo->query("SELECT * FROM `orders` WHERE `ID`=LAST_INSERT_ID()")->fetch(PDO::FETCH_ASSOC);
    

提交回复
热议问题