Skip to content
Advertisement

Two or more SQL queries in PHP function

Learning a graph-building PHP script I met a situation when PHP function performs only first query. Original code

JavaScript

ALL OK, everything works, I have a pie graph with correct data. But when I add one more query to update data before further processing

JavaScript
  • this case the function performs only first query adding +1 to all ‘marks’ – but instead of graph I have a white browser screen. When I comment in PHP code first query I have added – all OK again, I see a pie graph with new data. I was supposing I could request PHP function to perform two queries – first update something – and second collect updated data.

Is it an error in my syntax – or such a sequence of operations with MySQL queries does not work with PHP functions in principle ? Or we can suppose a flaw of a PHP script itself ? (what I doubt because everything works until I add one more query)

Thx for any opinion for better understanding or any idea what I should try,

In addition – next file catching data has the following code

JavaScript

etc – but I suppose function should return second query $result as above after first $update. May be I’m wrong but I try to understand where and why

As per comment – DataSource.php rules by dbConn and functions relating to MySQL queries – pls, see below

JavaScript

Advertisement

Answer

OK, so you already prepared and executed the query inside the badly named ->select() method.

As you are passing an UPDATE this time to the ->select() method, you will get a simple TRUE or FALSE back as thats all UPDATE and INSERT queries return.

So if you remove the $update->execute(); your error will likely disappear as well.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement