Skip to content
Advertisement

PHP MySQL INSERT return value with one query execution

Is there anything returned from MySQL/PHP on a INSERT query being executed? Here is my function which I have in a CLASS.

function mysqlQuery($query) {
   // Gets the results from the query
   $results = mysql_query($query, $this->connection);

   // Loops through the queried results as an multi-dimensional array
   while($rows = mysql_fetch_array($results, MYSQL_ASSOC)) {
      // Push results to single array
      $rs[] = $rows;
   }

   // Return results as array
   return $rs;
}

This is how I call the function

$rs = $dbh->mysqlQuery($query);

But executing a INSERT query the $rs returns nothing. Does my function need help or is this the default behavior? Any tips would be helpful as well.

Advertisement

Answer

INSERT just returns true or false. to actually return something useful, you will need a SELECT or similar query. there is no result to fetch with INSERT.

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