i have witten this php class, but i have problem using it,
<?php
class cs_mysql{
protected $configPath;
protected $db;
function __construct($cP = null){
$this->configPath = $cP;
require $this->configPath;
}
private function connection(){
$db = new mysqli(Config::get('dbHost'),Config::get('dbUser'),Config::get('dbPass'),Config::get('dbName'));
}
public function getRow($table){
$query = 'SELECT * FROM $table ORDER BY `id` DESC';
$sql = $this->db->query($query);
if(!$sql){
echo "FALSE";
}
}
}
?>
i don't know how to run db query : $sql = $this->db->query($query);
Change
$db = new mysqli(Config::get('dbHost'),Config::get('dbUser'),Config::get('dbPass'),Config::get('dbName'));
to
$this->db = new mysqli(Config::get('dbHost'),Config::get('dbUser'),Config::get('dbPass'),Config::get('dbName'));
$db is a property of the class. To access class properties (and methods) you have to reference the class instance using $this
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.