title: PHP MySQLi Undefined Method Error
body: <p>I'm creating some basic OO scripts using MySQLi and getting an Undefined Method error when I use any of stmt_init(), prepare() or query() ... Also getting an error with connect_errno(). I DO know that mysqli extension is enabled (uncommented) in my php.ini and phpinfo() has both mysqli and mysqlnd enabled ... So not sure why I can't access the methods/properties. The error I'm getting is:
  Fatal error: Call to undefined method mysqli::connect_error() </p>
  
  <pre><code>class db {
      public $host = 'localhost';
      public $username = 'root';
      public $password = '';
      public $database = 'molecule';
      public $mysqli = '';
      function __construct() {
          $this-&gt;mysqli = new mysqli($this-&gt;host, $this-&gt;username, $this-&gt;password, $this-&gt;database);
      return $this-&gt;mysqli;
      }   
  }
  
  class nodeModel {
      function __construct() {
          $this-&gt;mysqli = new db;
          if($this-&gt;mysqli-&gt;connect_error()){ printf("Database Connection failed: %s\n", $this-&gt;mysqli-&gt;connect_error()); }
      }
  
      function insertNode() {
          $this-&gt;insert = $this-&gt;mysqli-&gt;stmt_init();
          $this-&gt;insert-&gt;prepare("INSERT INTO node(node_name, node_link, node_comment) VALUES (?, ?, ?)");
          $this-&gt;insert-&gt;bind_param($this-&gt;node_name, $this-&gt;node_link, $this-&gt;node_comment);
          if($this-&gt;insert-&gt;execute()) {
              $this-&gt;insert_id = $this-&gt;mysqli-&gt;insert_id;
          }
          $this-&gt;insert-&gt;close();
          print_r($this-&gt;insert_id);
          return $this-&gt;insert_id;
      }
  </code></pre>
  
  <hr>
  
  <p>So, to get the insertNode() method to work ... these are the other methods I put in the nodeModel class</p>
  
  <pre><code>public function setNodeName($value) { $this-&gt;nodeName = $value; }
  public function setNodeLink($value) { $this-&gt;nodeLink = $value; }
  public function setNodeComment($value) { $this-&gt;nodeComment = $value; }
  public function getNodeName() { return $this-&gt;nodeName; }
  public function getNodeLink() { return $this-&gt;nodeLink; }
  public function getNodeComment() { return $this-&gt;nodeComment; }
  
  public $insert_id;
  function insertNode($nodeName, $nodeLink, $nodeComment) {
          $this-&gt;mysqli-&gt;stmt_init();
          $this-&gt;mysqli-&gt;prepare("INSERT INTO node(node_name, node_link, node_comment) VALUES (?, ?, ?)");
          $this-&gt;mysqli-&gt;bind_param($this-&gt;node_name, $this-&gt;node_link, $this-&gt;node_comment);
          if($this-&gt;mysqli-&gt;execute()) {
              $this-&gt;insert_id = $this-&gt;mysqli-&gt;insert_id;
          }
          $this-&gt;mysqli-&gt;close();
          print_r($this-&gt;insert_id);
          return $this-&gt;insert_id;
      }
  </code></pre>
  
  <p>How do I pass the variables into the method? I'm trying this ...</p>
  
  <pre><code>$connect = new db();
  $db = new nodeModel($connect);
  $db-&gt;setNodeName('My Node Title');
  $db-&gt;setNodeLink('My Node Link');
  $db-&gt;setNodeComment('My Node Comment. This one should be longer so I will write more stuff');
  $db-&gt;insertNode($db-&gt;getNodeName(), $db-&gt;getNodeLink(), $db-&gt;getNodeComment());
  </code></pre>
  
  <p>But that's not working. My confusion is really about OO scope inside of class methods ... I'm not sure what I'm I'm supposed to be passing.</p>