0

I have a simple sql function that works when called from wamp's mysql console. But when i try to fetch it in php it gives me error. I literally copy the content of mysqli_query and paste it into console and it works just fine, but in php gives me error. It sounds so simple, but I just can't resolve it whole day.

Summary of the code:

$ArrivalDate = mysqli_query(
              $dbCon,
              "select arrival('2017-03-09' , '2017-01-05' , '2017-01-05');"
                );

              $result = mysqli_fetch_row($ArrivalDate);

And this gives me that

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given

Dharman
  • 26,923
  • 21
  • 73
  • 125
wdc
  • 2,335
  • 1
  • 18
  • 38
  • Other queries with the same `$dbCon` works fine. – wdc Mar 09 '17 at 11:43
  • add `var_dump(mysqli_error($dbCon));` to see mysql errors. – Roland Starke Mar 09 '17 at 11:44
  • 1
    How about outputting `mysqli::$error()`? – syck Mar 09 '17 at 11:44
  • @syck @RolandStarke I got this when adding `var_dump` : `'Commands out of sync; you can't run this command now' (length=52)` – wdc Mar 09 '17 at 11:49
  • great so now you have a new thing to google... (i found http://stackoverflow.com/questions/614671/commands-out-of-sync-you-cant-run-this-command-now. and the first thing i would try is removing `;` inside your query) – Roland Starke Mar 09 '17 at 11:51
  • 1
    I suspect you have rows from a previous query, on that connection, that you haven't fetched yet. see the the question in the `Linked` section on the right hand column of this page. – Ryan Vincent Mar 09 '17 at 11:52
  • May be problem with $dbCon. Look at var_dump of $dbCon and $ArrivalDate – bigsiter Mar 09 '17 at 11:44

1 Answers1

1

I think your question is similar to this one: Mysqli Fetch Row Not Executing

Based on the answer from the link is you need to check if the query is correct or not.

So for your example it should be done:

$ArrivalDate = mysqli_query($dbCon,
                "select arrival('2017-03-09' , '2017-01-05' , '2017-01-05');"
                );

if($ArrivalDate){
    $result = mysqli_fetch_row($ArrivalDate);
}
else
{
exit('Error'); //Execute this code when the query failed
}

Also try to remove the semicolon ( ; ) inside your query statement suggested by thr commenter above

Community
  • 1
  • 1
Ricardo Raz
  • 473
  • 1
  • 9
  • 19