The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Class variable help

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #30191

    I’m trying to write a database crud class to get familiar with classes more for OOP. The problem lies in the $_mysql variable. It’s not being read by my read function. I’m not sure why, did I not declare something correctly? Here’s what I have:

    I have the start of my crud using a prepared statement.

    class Crud {

    protected $_mysql;

    public function __construct($host, $username, $password, $db) {
    $this->_mysql = new mysqli($host, $username, $password, $db) or die('There was a problem connecting to the database');

    public function read($tableName)
    $parameters = array();
    $results = array();

    $stmt = $_mysql->prepare("SELECT * FROM $tableName") or die('Problem preparing query');

    $meta = $stmt->result_metadata();

    while ( $field = $meta->fetch_field() ) {

    $parameters[] = &$row[$field->name];

    call_user_func_array(array($stmt, 'bind_result'), $parameters);

    while ( $stmt->fetch() ) {
    $x = array();
    foreach( $row as $key => $val ) {
    $x[$key] = $val;
    $results[] = $x;

    return $results;


Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.