This is probably very, very easy, but how do I execute two queries in the same PHP page?
I'm trying to do this...
<?PHP
error_reporting(E_ALL);
ini_set('display_errors', '1');
include 'db.php';
// FIRST QUERY;
$intCompanyID = 2612;
$sql = "CALL sp_get_company ($intCompanyID)";
$result = $connect->query($sql);
if ($result->num_rows > 0) :
$row = mysqli_fetch_assoc($result);
$company_name = $row["company_name"];
$contact_TEL = $row["contact_TEL"];
echo "company_name=".$company_name."<br />";
echo "contact_TEL=".$contact_TEL."<br />";
endif;
//SECOND QUERY;
$sql = "CALL sp_list_by_region (1)";
$result = $connect->query($sql);
if ($result->num_rows > 0):
while($row = $result->fetch_assoc()) {
echo "company_name = ".$row["company_name"]."<br />";
}
endif;
$connect->close();
?>
The first query works on its own. The second query works on its own. But when I run both I get the error "Trying to get property of non-object". Obviously I'm not reusing the connection properly. Can someone explain it to me?
Many thanks in advance.