資料庫lib
This commit is contained in:
parent
739cb7b9a1
commit
3441965fc0
11
Readme.md
11
Readme.md
@ -9,9 +9,14 @@ JGB Yuan 練習作業
|
|||||||
$ cp htdocs/config.sample.php htdocs/config.php
|
$ cp htdocs/config.sample.php htdocs/config.php
|
||||||
|
|
||||||
# 啟動伺服器
|
# 啟動伺服器
|
||||||
···
|
$ php -S 127.0.0.1:8000 -t htdocs
|
||||||
php -S 127.0.0.1:8000 -t htdocs
|
|
||||||
···
|
# 進入命令列
|
||||||
|
$ php -d auto_prepend_file=$PWD/htdocs/config.php -a
|
||||||
|
|
||||||
|
php > require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
|
||||||
|
php > $db = new MessageBoard\Database\DbMessage();
|
||||||
|
php > print_r($db->getList());
|
||||||
|
|
||||||
# 檔案結構
|
# 檔案結構
|
||||||
|
|
||||||
|
@ -2,19 +2,22 @@
|
|||||||
|
|
||||||
require_once 'config.php';
|
require_once 'config.php';
|
||||||
require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
|
require_once FOLDER_ROOT.'/lib/Database/DbMessage.php';
|
||||||
|
use MessageBoard\Database\DbMessage;
|
||||||
|
|
||||||
$list = [
|
$db = new DbMessage();
|
||||||
[
|
$list = $db->getList();
|
||||||
'id' => 1,
|
// $list = [
|
||||||
'title' => 'text',
|
// [
|
||||||
'updated_at' => '2020-04-01 12:13',
|
// 'id' => 1,
|
||||||
],
|
// 'title' => 'text',
|
||||||
[
|
// 'updated_at' => '2020-04-01 12:13',
|
||||||
'id' => 2,
|
// ],
|
||||||
'title' => 'text',
|
// [
|
||||||
'updated_at' => '2020-04-01 12:13',
|
// 'id' => 2,
|
||||||
],
|
// 'title' => 'text',
|
||||||
];
|
// 'updated_at' => '2020-04-01 12:13',
|
||||||
|
// ],
|
||||||
|
// ];
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -14,9 +14,15 @@ class DbMessage extends Database
|
|||||||
* @param integer $count 此查詢要列出幾筆
|
* @param integer $count 此查詢要列出幾筆
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getList(int $limit, int $count)
|
public function getList(int $limit=null, int $count=null)
|
||||||
{
|
{
|
||||||
return [];
|
$sqlString = "SELECT * FROM `".$this->table('message')."`";
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$queryResultAll = $query->fetchAll();
|
||||||
|
|
||||||
|
return $queryResultAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,19 +33,10 @@ class DbMessage extends Database
|
|||||||
*/
|
*/
|
||||||
public function getDataByid($id)
|
public function getDataByid($id)
|
||||||
{
|
{
|
||||||
$sqlString = "SELECT `UID`, `UPassword`, ".
|
$sqlString = "SELECT * FROM `".$this->table('message')."` WHERE id = :id";
|
||||||
"`group`.`GID`, `group`.`GName`, `class`.`CID`, `class`.`CName`, ".
|
|
||||||
"`UEnabled`, `UBuildTime`, `UModifyTime`, ".
|
|
||||||
"`LMode`, `MMode`, `UEnable_NoAppoint`, ".
|
|
||||||
"`UNickname`, `URealName`, `UEmail`, `UMemo` ".
|
|
||||||
"FROM `".$this->table('user')."` AS `user` ".
|
|
||||||
"LEFT JOIN `".$this->table('user_auth_group')."` as `group` ".
|
|
||||||
"ON `group`.`GID` = `user`.`GID`".
|
|
||||||
"LEFT JOIN `".$this->table('user_class')."` as `class` ".
|
|
||||||
"ON `class`.`CID` = `user`.`CID`".
|
|
||||||
"WHERE ".$where;
|
|
||||||
|
|
||||||
$query = $this->connDB->prepare($sqlString);
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":id", $id);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
||||||
$queryResultAll = $query->fetchAll();
|
$queryResultAll = $query->fetchAll();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user