0

I am sure the error is staring me in the face, but I will still ask it, as I have spent several hours already trying to figure it out. I don't know why, but the query causes HTML to stop rendering entirely. Not just within the PHP tag, but all HTML. Below is a very trimmed down version of my code, just enough to get the error. What should be displayed is the number 1 followed by a var_dump, then 2, var_dump, etc... but all I get is 1, then the error.

<?php
class Calendar {
 private $DBConnect = NULL;

    function __construct() {
        $ErrorMsgs = array();
        $DBConnect = new mysqli("localhost", "user", "pass", "db");
        if ($DBConnect->connect_error)
            $ErrorMsgs[] = "The database server is not available. Connect Error is " . $mysqli->connect_errno . " " . $mysqli->connect_error . ".";
        $this->DBconnect = $DBConnect;  
    }

    public function getMonthlyCalendar($Year, $Month) {
        for ($i = 1; $i <= 31; ++$i) {
            echo $i;
            $SQLstring = "SELECT EventID, Title FROM event_calendar WHERE EventDate='2014-05-$i'";
            $QueryResult = $this->DBConnect->query($SQLstring);
            var_dump($QueryResult);
        }
    }
}

$Calendar = new Calendar();
$Calendar->getMonthlyCalendar(2014, 5);
?>

2 Answers2

0

You have a typo in your code:

you declared

$this->DBconnect = $DBConnect;  

but then you used

$QueryResult = $this->DBConnect->query($SQLstring);

with C in DBConnect uppercase.

Paolo
  • 15,233
  • 27
  • 70
  • 91
  • Oh. My. God. I've spent hours looking at this code, reworking it dozens of times, echo this, dump that. You saw it in 6 minutes. What's funny is I only included the constructor here for completeness. Thank you so much! – mrtarantula May 10 '14 at 23:43
-1

that error message is usually an error in the query. if you are using phpmyadmin copy your query, and run it in your phpmyadmin query box and see if it returns results.if your query works then you know is an error in your connection script

  • The error comes from $this->DBConnect not being an object. It has nothing to do with the query. If the query was the problem, he'd get a different error. – Cully May 10 '14 at 23:27
  • so its an error in the connection script ..... – user2976773 May 10 '14 at 23:29
  • It's a typo. But even if it wasn't, your answer wouldn't be accurate. That error just isn't produced by a problem with the query. – Cully May 10 '14 at 23:30
  • thats why the problem is the connection script..... – user2976773 May 10 '14 at 23:32
  • Thanks for the response! I thought it was a query problem too. I spent a long time double and triple-checking all the SQL. Turns out it was just a typo in the constructor. – mrtarantula May 10 '14 at 23:48