Skip to content

Commit 0980476

Browse files
committed
新增 SQLite 驱动方式
1 parent 332481b commit 0980476

File tree

13 files changed

+207
-161
lines changed

13 files changed

+207
-161
lines changed

.idea/ORM.iml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/php.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 165 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

App/Controller/apiController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class apiController {
99
*/
1010
public function test($id){
1111
// echo $_SERVER['REQUEST_METHOD'];
12+
$test = Demo::all()->paginate(3);
13+
print_r($test);
1214
}
1315

1416
// 查询类方法演示
@@ -33,6 +35,12 @@ public function whereRaw(){
3335
print_r($resultObjectArray);
3436
}
3537

38+
public function all(){
39+
// 显示全部数据
40+
$resultObjectArray = Demo::all();
41+
print_r($resultObjectArray);
42+
}
43+
3644
public function raw(){
3745
// 执行SQL语句
3846
$sqlStatement = 'SELECT * FROM {table} WHERE author LIKE "Rytia"';

App/System/Collection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ public function paginate($pageNum, $furtherPageInfo = true){
319319
// 添加分页的属性
320320
$this->collectionPages = new \stdClass();
321321
$this->collectionPages->currentPage = $currentPage;
322-
$this->collectionPages->totalPages = $total;
323-
$this->collectionPages->hasNext = (ceil($total / $pageNum) > $currentPage) ? "true" : "false";
322+
$this->collectionPages->totalItems = $total;
323+
$this->collectionPages->totalPages = ceil($total / $pageNum);
324+
$this->collectionPages->hasNext = ($this->collectionPages->totalPages > $currentPage) ? "true" : "false";
324325
$this->collectionPages->nextUrl =($this->collectionPages->hasNext == "true") ? parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH).'?page='.($currentPage+1) : NULL;
325326
}
326327

App/System/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
namespace System;
3-
use System\DatabaseDriver\pdo_mysql;
3+
use System\DatabaseDriver\pdo_sqlite;
44
class Database{
55

66
public $PDOStatement;
@@ -14,7 +14,7 @@ class Database{
1414

1515
public function __construct() {
1616
// 使用 pdo 进行处理
17-
$this->PDOConnect = (new pdo_mysql())->connect;
17+
$this->PDOConnect = (new pdo_sqlite())->connect;
1818
}
1919

2020
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
namespace System\DatabaseDriver;
3+
4+
class pdo_sqlite{
5+
6+
public $connect;
7+
8+
public function initialConnect($file) {
9+
// 创建 pdo 链接
10+
$link = 'sqlite:'.$file;
11+
try {
12+
$db = new \PDO($link);
13+
$db->exec("SET NAMES utf8");
14+
}
15+
catch (\PDOException $e) {
16+
echo 'Connection Failed: ' . $e->getMessage();
17+
}
18+
finally{
19+
return $db;
20+
}
21+
}
22+
23+
public function __construct(){
24+
$this->connect = self::initialConnect('orm.sqlite3.db');
25+
}
26+
27+
}

0 commit comments

Comments
 (0)