0
我一直在使用PHP一段時間,但直到最近纔開始着眼於它的OOP方面。我想創建一個數據庫類,我可以存儲我的查詢功能,如更新,刪除,選擇,插入。在PHP中創建數據庫類
林不知道如果我試圖運行這個對什麼我做錯了,會有人來看看這個,給我一些建議,請
當我試圖運行此我得到以下錯誤雖然:
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)
HTML:
<?php
require_once("class.Database.php");
?>
<html>
<head>
<title>Database's and Classes</title>
</head>
<body>
<?php
select("cars", "make");
?>
</body>
</html>
到目前爲止,我已經爲我的PHP:
<?php
require_once __DIR__ . '../../../cfg/cfg.php';
class Database {
private $dbConn; //stores the database connection
public function __construct(){
global $cfg;
$host = $cfg['db']=>host;
$user = $cfg['db']=>user;
$pass = $cfg['db']=>pass;
$db = $cfg['db']=>db;
mysqli_connect($host, $user, $pass, $db) or die("Couldn't connect");
}
public function insert($table, $column, $value){
$result = mysqli_query(INSERT into $this=>table($this=>column) VALUES ($this=>value));
return $result;
}
public function select($table, $column){
$result = mysqli_query(SELECT $this=>column FROM $this=>table);
return $result;
}
public function update($table, $column, $value, $whereCol, $whereVal){
$result = mysqli_query(UPDATE $this=>table set $this=>column = $this=>value WHERE $this=>column = $this=>value);
return $result;
}
public function delete($table, $column, $value){
$result = mysqli_query(DELETE FROM $this=>table WHERE $this=>column = $this=>value);
return $result;
}
}
?>
我會從這裏開始http://php.net/manual/en/language.types.array.php之後繼續閱讀這個http://php.net/manual/en/language.oop5 .php – PeeHaa
'=>'用於在數組中分配鍵::值對,' - >'用於從對象中獲取變量/屬性(即OOP)。 – Darren