[英]calling a function from php class
我有這個php類,但是我在使用它時遇到了問題,
<?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";
}
}
}
?>
我不知道如何運行數據庫查詢: $sql = $this->db->query($query);
更改
$db = new mysqli(Config::get('dbHost'),Config::get('dbUser'),Config::get('dbPass'),Config::get('dbName'));
至
$this->db = new mysqli(Config::get('dbHost'),Config::get('dbUser'),Config::get('dbPass'),Config::get('dbName'));
$ db是該類的屬性。 要訪問類屬性(和方法),必須使用$this
引用類實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.