Search the Community
Showing results for tags 'stored procedure'.
-
I have this stored procedure that has 2 parameters, the first one is the cartId(which is the IN) and I have the newOrderId(which is the OUT). Now, I know that the inCartId is the cart id which will come from the form or whatever means the cart is been access but I don't understand the OUT newOrderId since that is what MySQL will return. Now, in the PHP calling this Stored procedure, it will look like this. $sql = 'CALL create_order(:cart_id, "What will be here")// The cart_id is what PHP will pass to MySQL, but what will be passed to the 2nd argument since does not before hand what MySQL will return. CREATE PROCEDURE create_order( IN inCartId int, OUT newOrderId int ) BEGIN -- Insert a new record into orders and obtain the new order ID INSERT INTO orders (created_on) VALUES (NOW()); -- Obtain the new Order ID SELECT LAST_INSERT_ID() INTO newOrderId; -- Insert order details in order_detail table INSERT INTO order_detail ( order_id, product_id, attributes, product_name, quantity, unit_cost ) SELECT orderId, p.id, sc.attributes, p.name, sc.quantity, COALESCE( NULLIF( p.discounted_price, 0 ), p.price ) AS unit_cost FROM shopping_cart sc INNER JOIN products p ON sc.product_id = p.id WHERE sc.cart_id = inCartId AND sc.buy_now; -- Save the order's total amount UPDATE orders SET total_amount = ( SELECT SUM( unit_cost * quantity ) FROM order_detail WHERE order_id = orderId ) WHERE id = orderId; -- Clear the shopping cart CALL shopping_cart_empty(inCartId); END
- 1 reply
-
- stored procedure
- pdo
-
(and 2 more)
Tagged with:
-
On the Shipping Information page, when a phone number is provided that has an area code greater than "214", after the "continue on to billing" button is clicked, the following error results: "An error occurred in script 'C:\wamp64\www\effortlessECommerce\effortless_ecommerce_2nd\ex2\html\checkout.php' on line 158: Your order could not be processed due to a system error." This is because the add_customer stored procedure's "p" (aka "phone") parameter is stored as an "int", and ints have a maximum value of 2,147,483,647. Therefore, a phone number with an area code larger than 214 will fail. I fixed the error like this: 1) Go to PHPMyAdmin. 2) Click "Procedures" 3) Click the "edit" button next to "add_customer" 4) Scroll down to the second to last row and change parameter "p" from an "int" to a "char". 5) Change parameter "p"'s "length/values" field from blank to "10" (no quote marks). 6) Click "Go" button. Now it "works on my machine".
- 2 replies
-
- stored procedure
- add_customer
- (and 5 more)
-
Hi Chapter 8 index.php-home page Display where a few items on sale are show I am using $r = mysqli_query($dbc, 'CALL select_sale_items(true)');.....this is not formatting the price(ie 500) I change to $r = mysqli_query($dbc, 'CALL select_sale_items(false)');...this is formatting the price(ie$5.00) I am thinking there is an error in my select_sale_items stored procedure in the IF beginning section.. I have not found the error.. My Question is... Could I be not seeing the error in this stored procedure? Thank you
-
I have gone through the book back to back and I found the tips and trciks very useful. However, I would like to develop further on the example give in the second site. I have a situation where a product has many sizes (different sizes with different stock values). The database structure and stored procedure described in the example is certainly not applicable here. I am thinking of creating a join table, removing the stock columm from the product table and add it to this join table but I am not sure how to write stored procedures that fetches same product, diffrent sizes and stock. I would appreciate if someone could help out.
- 1 reply
-
- databse design
- mutiple sizes
-
(and 2 more)
Tagged with: