Fatal error: Call to a member function bind_param() on boolean in [path to PHP the file]

Fatal error: Call to a member function bind_param() on boolean in [path to PHP the file]

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Fatal error: Call to a member function bind_param() on boolean in [path to PHP the file]

When you encounter a Fatal error: Call to a member function bind_param() on boolean, your immediate instinct might be to check for SQL syntax errors or missing tables. However, this specific exception usually points to a much more subtle issue: the database connection has already failed or closed before the query execution logic runs. In the code provided, the culprit is not the SELECT statement itself, but rather the state of $this->db->conn.

The error message indicates that PHP expects an object instance from MySQLi, but it is receiving a boolean value instead. This happens because the variable holding your connection was overwritten or reassigned to a failure state prior to the function call.

The Hidden Failure in Connection Initialization

Let's look closely at the Database class constructor:

$this->conn = new MySQLi(
  $this->data->getData('database', 'hostname'), 
  $this->data->getData('database', 'username'), 
  $this->data->getData('database', 'password'), 
  $this->data->getData('database', 'database')
);

if ($this->conn->errno) {
    __('failed.db.connection', $this->conn->errno);
}

The logic here attempts to handle connection failures, but it does so incorrectly. When new MySQLi() fails (for example, due to an incorrect hostname, authentication error, or the database not existing), the MySQLi constructor returns a false boolean value rather than throwing an exception immediately in older PHP versions.

The critical flaw is the subsequent line: $this->conn->errno. You cannot access properties on a boolean object. If the connection failed, $this->conn is false. Attempting to read $this->conn->errno triggers a fatal error of its own (usually "Call to a member function ... on false"), but in your specific stack trace, the error occurs later in the query execution block because the code assumes success.

Even if you believe the connection works (as evidenced by your manual tests), the state passed to your getSetting function might be corrupted. If the constructor throws an exception that is not caught, or if the error handling logic inadvertently overwrites $this->conn with a string or null in a different version of your framework, you end up calling bind_param() on a boolean.

Fixing the Connection Check Logic

To resolve this, you must verify the return value of the MySQLi constructor explicitly before attempting to use it. You should never assume that because no exception was thrown, the connection is valid.

Update your Database class constructor to check the result of the instantiation directly:

public function __construct($data) {
    $this->data = $data;
    
    // Attempt to establish the connection
    $this->conn = new MySQLi(
      $this->data->getData('database', 'hostname'), 
      $this->data->getData('database', 'username'), 
      $this->data->getData('database', 'password'), 
      $this->data->getData('database', 'database')
    );

    // Explicitly check if the connection object is valid
    if (!$this->conn) {
        // Handle the failure gracefully, perhaps logging or throwing a custom exception
        throw new Exception("Database connection failed: " . mysql_error() ?? mysqli_connect_error());
    }

    if ($this->conn->errno) {
        __('failed.db.connection', $this->conn->errno);
    }

    date_default_timezone_set('Europe/Amsterdam');
}

By adding if (!$this->conn), you ensure that $this->conn is never used as an object until it has successfully instantiated. This prevents the scenario where bind_param() is called on a boolean.

Refactoring the Query Logic

While fixing the connection state is the primary solution, there are additional improvements to make in your getSetting function regarding resource management and flow control. Your current implementation calls bind_result(), store_result(), and fetch() inside an if block where only one row is expected. The while loop will execute once, return the value, and then the rest of the logic inside that loop is skipped.

However, a more robust pattern for retrieving settings involves checking the result object directly rather than relying solely on row counts, and ensuring proper cleanup:

public function getSetting($setting)
{
    // Prepare the statement
    $stmt = $this->db->conn->prepare('SELECT value, param FROM ws_settings WHERE name = ?');
    
    if (!$stmt) {
        throw new Exception("Query preparation failed");
    }

    $stmt->bind_param('s', $setting);
    $stmt->execute();
    
    // Check execution status before binding results
    if ($stmt->num_rows() > 0) {
        $stmt->bind_result($value, $param);
        $stmt->fetch();
        
        $stmt->store_result(); // Not strictly necessary here as we already fetched

        return $value;
    }

    // Handle missing setting
    __('invalid.setting.request', $setting);
    
    return null;
}

Conclusion on Stability

The error Call to a member function bind_param() on boolean is almost exclusively caused by a failed database connection where the error handling logic fails to detect the failure state. By explicitly validating the connection object immediately after instantiation and ensuring that the $this->db->conn property holds a valid MySQLi instance, you eliminate this class of fatal errors. Always treat constructor return values as potentially false in MySQLi interactions unless your PHP version guarantees an exception on failure.

Our network