pdo prepare multiple queries

Solutions on MaxInterview for pdo prepare multiple queries by the best coders in the world

showing results for - "pdo prepare multiple queries"
Adelia
30 Apr 2017
1<?php
2
3
4
5try {
6
7        $db = new Database(); //Create a new object of type Database establishing a connection to the MySQL database
8
9
10        $query = $db->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)");
11
12        $query->execute(array( /* your values*/ ));
13
14
15        $lastId = $db->lastInsertId(); // fetch last insert id, after success.
16
17
18        $order = $db->prepare("SELECT * FROM `orders` WHERE `ID`=?");
19        $order->bindValue(1, $lastId);
20        $order->execute();
21        //Fetch your records and display.
22
23
24}
25catch (PDOException $e) {
26        echo "Error : " . $e->getMessage();
27
28}
29
30?>
31