Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is mysql_query under PHP a blocking function?

Tags:

php

mysql

Suppose I am executing several queries on the server using mysql_query. The results of every query affect the subsequent query. Will every call of mysql_query be completely executed before control moves on to the next one?

Edit: I forgot to mention, I am not using a transactional storage engine.

like image 239
susmits Avatar asked Apr 16 '10 12:04

susmits


People also ask

What is mysql_query () function?

mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it.

Is mysql_query deprecated?

This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.

What sort of value does the mysql_query () function return?

mysql_query() returns TRUE (non-zero) or FALSE to indicate whether or not the query succeeded. A return value of TRUE means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned.

What does $query do in PHP?

Definition and Usage. The mysqli_query() function accepts a string value representing a query as one of the parameters and, executes/performs the given query on the database.


1 Answers

Yes, the MySQL server must return data and complete the query before PHP will progress to the next action, be it assigning the return value or progressing to the next line of code.

mysql_query( "INSERT INTO y VALUES (x,1)" );
mysql_query( "SELECT x FROM y WHERE z=1" );
mysql_query( "UPDATE y SET x=x+1 WHERE z=1" );
mysql_query( "SELECT x FROM y WHERE z=1" );

x will be 1, then 2, and by the time of the fourth statement 2 will be returned to the script. It is not possible to run the queries in parallel in a single PHP script - this would require parallel execution or threading in another language (i.e. Java).

like image 69
Andy Avatar answered Sep 18 '22 13:09

Andy