本文目錄一覽:
- 1、錯誤位置: FILE:/www/shidu/ThinkPHP/Lib/Core/Db.class.php LINE:640 在線等 急啊。
- 2、php.Db.class.寫法
- 3、錯誤位置: FILE: D:\wwwroot\navicle\t\Lib\Core\Db.class.php LINE: 214如何解決的
- 4、新手求助,有Db.class.php,Class Db’not found
錯誤位置: FILE:/www/shidu/ThinkPHP/Lib/Core/Db.class.php LINE:640 在線等 急啊。
這種的肯定不是這個db.class.php的錯誤
看看調試模式是否開啟了,沒有開啟的建議開啟就能看到詳細的報錯信息了
或者貼出你的代碼
php.Db.class.寫法
?php
class Db{
public $host;
public $username;
public $password;
public $database;
public $conn;
public $table;
public $sql;
public $field = ‘*’;
function __construct($host,$username,$password,$database){
$this-host = $host;
$this-username = $username;
$this-password = $password;
$this-database = $database;
$this-connect();
}
function connect(){
$this-conn = new mysqli($this-host, $this-username, $this-password,$this-database);
if ($this-conn-connect_error) {
die(“連接失敗: ” . $this-conn-connect_error);
}
}
function M($table){
$this-table = $table;
return $this;
}
function where($array){
$this-sql = ”;
$sql = ‘where ‘;
$one = ”;
if($array){
if(is_array($array)){
foreach($array as $key=$vo){
$one .= ‘`’.$key.’` = “‘.$vo.'” and’;
}
$one = trim($one,’and’);
$sql .= $one;
$this-sql = $sql;
}else{
$sql .= $array;
$this-sql = $sql;
}
}
return $this;
}
function add($array){
$sql = ‘insert into `’.$this-table.’` (‘;
$one = ”;
$two = ”;
if($array){
if(is_array($array)){
foreach($array as $key=$vo){
$one .= ‘`’.$key.’` ,’;
$two .= ‘”‘.$vo.'”,’;
}
$one = trim($one,’,’);
$two = trim($two,’,’);
if($one $two){
$sql .= $one.’) values (‘.$two.’)’;
$this-sql = $sql;
$r = $this-conn-query($this-sql);
if($r){
return mysqli_insert_id($this-conn);
}else{
return false;
}
}
}else{
exit(‘非數組’);
}
}else{
exit(‘數組為空’);
}
}
function select(){
$array = ”;
$sql = ‘select ‘.$this-field.’ from `’.$this-table.’`’.$this-sql;
$result = $this-conn-query($sql);
if ($result-num_rows 0) {
while($row = $result-fetch_assoc()) {
$array[] = $row;
}
}
return $array;
}
function find(){
$row = ”;
$sql = ‘select ‘.$this-field.’ from `’.$this-table.’`’.$this-sql.’limit 1′;
$result = $this-conn-query($sql);
$row = $result-fetch_assoc();
return $row;
}
function edit($array){
$sql = ‘update `’.$this-table.’` set ‘;
$one = ”;
if($array){
if(is_array($array)){
foreach($array as $key=$vo){
$one .= ‘`’.$key.’` = “‘.$vo.'”,’;
}
$one = trim($one,’,’);
$sql .= $one.’ ‘.$this-sql;
}else{
$sql .= $array.’ ‘.$this-sql;
}
$r = $this-conn-query($sql);
if($r){
return true;
}else{
return false;
}
}else{
exit(‘未接收到參數’);
}
}
function delete(){
$sql = ‘delete from `’.$this-table.’` ‘;
$sql .= $this-sql;
$r = $this-conn-query($sql);
if($r){
return true;
}else{
return false;
}
}
function order($data){
$this-sql = $this-sql.’ order by ‘.$data;
return $this;
}
function limit($data){
$this-sql = $this-sql.’ limit ‘.$data;
return $this;
}
function field($data){
$this-field = $data;
return $this;
}
}
$db = new Db(‘localhost’,’root’,’root’,’database’);
?
錯誤位置: FILE: D:\wwwroot\navicle\t\Lib\Core\Db.class.php LINE: 214如何解決的
1:用戶名密碼不對
2:權限設置的有問題,你可以在 phpmyadmin里,找到用戶列表,然後設置權限。
新手求助,有Db.class.php,Class Db’not found
有 Db.class.php ,在實際使用時,還需要 include 文件,而且源代碼中要確實定義了 class db。
原創文章,作者:RXGO,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/137156.html