0

can someone explafind out WHY i have a query: SELECT something FROM MyTable

while ($stmt->fetch()) {
   // EVERYTHING I DO HERE IS FINE
   ...
   $ss['ss_id'] = $ss_id;

   //THIS IS THE CALL I AM ASKING ABOUT
   $ss['crew'] = $this->getStarshipTeam($ss_id); 
}
function  getStarshipTeam($starship_id) {
            //THIS QUERY WORKS IN MYSQL WORKBENCH TEST
            $q = "SELECT u.nome, u.cognome
                  FROM users u, user_props
                  WHERE user_props.starship_id=?
                  AND user_props.id_user=u.id_user
                  ORDER BY u.cognome ASC
                  ";

            $crew = [];
            // RETURNS $stmt = false when run in the code!!! :(
            if($stmt = $this->conn->prepare($q)) {
                $stmt->bind_param("i", $starship_id);
                $stmt->execute();
                $stmt->bind_result($nome, $cognome);
                while ($stmt->fetch()) {
                    array_push($crew, $nome." ".$cognome);
                }
            }
            else {
                die('error');
            }
            return $crew;
        }

basically it is a fetch loop which retrieves $ss_id; and calls the function to do the parallel query...

any hint why this happens?

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Have you checked the DB is properly connected? Check for errors using `mysqli_connect_errno()` – Manish Pareek Oct 16 '20 at 10:21
  • **We** can't tell you the problem just from looking at this, no. **You** can easily find out the error though. Ensure that PHP is set up to log exceptions, and that mysqli is set to throw exceptions when SQL errors occur. If you need help setting those things up, you can use the following guides: https://stackify.com/php-error-logs-guide/ (php error logging/reporting) https://stackoverflow.com/a/14578644/5947043 (mysqli exception handling). Once you do that, your code should report a meaningful error message in the log. (This should be part of your standard set-up anyway really!) – ADyson Oct 16 '20 at 10:52
  • How do you know it returns false? – Your Common Sense Oct 16 '20 at 10:54
  • printing $stmt :) – Matteo Maria Ambrogi Oct 16 '20 at 11:24

0 Answers0