PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi - I'm struggling to tell what's failing so I realised I don't know enough about how php executes mysql queries.
Will everything happen in order, or could the javascript at the bottom render/fire without the mysql being successful?
Additionally - what's the best way to fire/react to a timeout (does mysql_error() provide that?)
thanks
Ok thanks... so it waits?
Does the html output render only if the statements preceeding it succeed?
If the server takes time to respond, does nothing else happen until the query has resolved true or false?
It could, for example, send the request and continue running the rest of the code. Then when the server responds fire the error.
I'm trying to think of a scenario where a linear program continues when one of its commands is waiting for a response. I can't think of one off the top of my head. Mostly what happens in such programs is that commands are run in a sequence from the top of the program to the bottom. If the command on line 13 is "connect to the database" and the database takes ages to respond, the command on line 14 won't run until the answer has come back. Even if you background part of the program it will still wait for a response.
Well, Ajax will send off a request and continue rendering the page. I also wasn't sure if the HTML content would be treated in the same way as the php. All possibilities tend to go through your mind when things stop working! Thanks.
I0printRob wrote:Ok thanks... so it waits?
Does the html output render only if the statements preceeding it succeed?
If the server takes time to respond, does nothing else happen until the query has resolved true or false?
It could, for example, send the request and continue running the rest of the code. Then when the server responds fire the error.
As litarena said, nothing else happens. If it were otherwise, none of the branching logic would make any sense. It's the same with Ajax. The PHP action is to send data to the server, then it continues with the next step. The fact that the server may send some data back later is a separate activity. That's why it's called "asynchronous." But as far as PHP is concerned it did it's action by sending the data. If the sending action failed, for some reason, the script would stop. Yes, everything stops when a die() operation is executed. That's why it's called "die." You use this syntax when you want the execution to halt because it would make no sense to continue. If you want to proceed with the rest of the PHP and HTML, you would not use die() syntax.