well I am having a problem with my class I made to connect to my DB ok here is the class

class database
{
private $db_host = 'localhost';
private $db_user = 'root';
private $db_pass = 'McSteel8';
private $db_database = 'cmte';
public function connect() 
{
$this->link = mysqli_connect($this->db_host, $this->db_user, $this->db_pass);

mysqli_select_db($this->link, $this->db_database


}
public function select($table)
{

$sql = "select * from '$table'";
$result = mysqli_query($this->link, $sql);
if(!$result)
{
echo 'problems';
exit();
}
$row = mysqli_fetch_array($result);
return $row;
}
}

my problem is the mysqli_query for some reason it is not using $this->link how do I make it work?

Recommended Answers

All 2 Replies

line 11, closing bracket is missing.

//mysqli_select_db($this->link, $this->db_database 
mysqli_select_db($this->link, $this->db_database);

line 19:
try changing it from

//$sql = "select * from '$table'";
//TO
$sql = "select * from $table"; //without single quotes. table name do not need to be enclosed with single quotes. 
//OR
$sql = "select * from {$table}";

hope this helps.

thanks should have known that one!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.