I am working on an e-commerce page. I have written a piece of code to get a list of products from my database based on which shopping cart they are in. There are three tables, one for the shopping carts, one for the items in each cart and one listing the details of each product. The session id is stored in the table listing the carts.
I have written the following code in one part of a php file:
$sessionId = session_id();
$selStr = "SELECT cart_items.quantity, products.price, products.discount
FROM cart_items JOIN carts ON carts.id = cart_items.carts_id
JOIN products ON cart_items.products_id = products.id
WHERE session_id='".$sessionId."';";
$result = mysql_query($selStr);
When I get this page in the browser, the request times out on the server and it returns an error:
Fatal error: Maximum execution time of 30 seconds exceeded
I ran this SQL statement using phpMyAdmin and the code runs fine. In fact, it returns immediately. Also, if I break up the SQL statement and retrieve info from the tables one at a time with seperate calls to MySQL, then no timeout occurs. I am writing this SQL code to eliminate extraneous amounts of code in my files.
Is there a reason why the call to the MySQL database takes longer in the PHP code only?
EDIT: To clarify the question, I mean to ask why doesn't the MySQL call return immediately in my php code? Is there something stopping it from returning at all? A security issue maybe?