0

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?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by tape enterprise
0

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.

Edited by kekkaishi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.