Answer the question
In order to leave comments, you need to log in
How to query the database in this case?
db.php file:
require 'config.php';
/**
*
*/
class dbConnect
{
protected $table = '';
function __construct($table)
{
$this->table = $table;
}
public function dbConnect() {
$db = new mysqli (DB_HOST, DB_USER, DB_PASS) or die (' WRONG CONNECTION PARAMETERS');
$db->select_db($this->table) or die (' WRONG TABLE');
$db->set_charset('utf-8');
}
}
?>
<?php
require 'db.php';
#DATABASE CONNECT;
$testConnect = new dbConnect('test');
$testConnect->dbConnect();
?>
Answer the question
In order to leave comments, you need to log in
Or add something like return $db to dbConnect , and then, respectively, $db = $testConnect->dbConnect();
or
public $db = '';
...
$this->db = new mysqli(...
$testConnect->db->...
And another question immediately arose.
Made:
....
public function dbConnect() {
...
...
return $db;
}
}
$db = $testConnect->dbConnect();
$sql = $db->query('SELECT name FROM qwert');
print_r($sql);
mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 1 [type] => 0 )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question