Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.