Jump to content

mysqli and simple class


asucrews

Recommended Posts

okay so were did i go worng? i am getting this error...

"mysqli_query() expects parameter 1 to be mysqli, null given in test.php on line 9"

 

Test.php

<?php
require("database.inc");

$database = new MySQLDB();

$compnayid = 1;

$sql = "SELECT * FROM  `studios` WHERE  `companyID` = $companyid";
$result = mysqli_query($database->MySQLDB(),$sql);
echo $result;

?>

 

database.inc

<?php

require("constants.inc");

class MySQLDB{
public $connection;	

public function showerror()
{
	if (mysqli_connect_error()){
		die ("Error". mysqli_connect_errno() . " : " . mysqli_connect_error());	
	}else{
		die ("Could not connect to the MySQL Database");	
	}
}
        
public function MySQLDB() {
	$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS) or self::showerror();
        mysqli_select_db($this->connection, DB_NAME) or self::showerror();
}

}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/138555-mysqli-and-simple-class/
Share on other sites

wow!!!! why does it seem to me the simple things that get me all that time  ???

 

THANKS!!!!!

 

It's not just you trust me. I could spend hours looking at my own code and miss something that small and I should have caught in the first 5 seconds of looking at it. That is just how your mind works. Sometimes printing the problem code on paper helps too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.