connection class issue
Posted: Thu Nov 19, 2015 10:00 pm
I have a test database called Gas with one table called stats. I am trying to
I have a class to connect to a database like so
The var dump above gives me this
string 'SELECT * FROM stats'
but I am getting this error message on the index, I have marked the error line above with a (47)
Warning: mysqli_query() expects at least 2 parameters, 1 given
in my index file, I did this
I am getting the error "No connection". I don't understand why it's not connecting.
I have a class to connect to a database like so
Code: Select all
class database {
function connect(){
$server = "private";
$db_user = "private"; // Enter your username
$db_pass = "private"; // Enter your password
$db_name = "private"; // Enter your database name
$mysqli = new MySQLi($server, $db_user, $db_pass, $db_name);
if($mysqli->connect_errno){
echo "Failed to connect to database: (" . $mysqli->connect_errno . ")" . $mysqli->connect_error;
}
}
public function select($table, $rows = '*', $where = null, $order = null){
$q = 'SELECT '.$rows.' FROM '.$table;
if($where != null)
$q .= ' WHERE '.$where;
if($order != null)
$q .= ' ORDER BY '.$order;
(47) $query = mysqli_query($q);
var_dump($q);
}
$mysqli = new database;
string 'SELECT * FROM stats'
but I am getting this error message on the index, I have marked the error line above with a (47)
Warning: mysqli_query() expects at least 2 parameters, 1 given
in my index file, I did this
Code: Select all
$conn = $mysqli->connect();
if($conn){
echo "Connected";
} else {
echo "no connection";
}
$mysqli->select('stats','*');
?>