Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
rebuild db
Browse files Browse the repository at this point in the history
  • Loading branch information
suyar committed Jul 17, 2021
1 parent 7ed6f1a commit 104bb13
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 38 deletions.
69 changes: 34 additions & 35 deletions kernel/db/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,7 @@ public function slavePdo()
}
return $this->_slave->pdo();
}

/**
* 创建查询构造器
* @return Query
*/
public function createQuery()
{
return new Query($this);
}



/**
* 返回最后插入行的自增ID
* @return string 返回ID
*/
public function lastInsertId()
{
return $this->masterPdo()->lastInsertId();
}

/**
* 启动一个事务
* @return bool 成功时返回true,或者在失败时返回false
Expand All @@ -156,7 +136,7 @@ public function begin()
{
return $this->masterPdo()->beginTransaction();
}

/**
* 提交一个事务
* @return bool 成功时返回true,或者在失败时返回false
Expand All @@ -165,7 +145,7 @@ public function commit()
{
return $this->masterPdo()->commit();
}

/**
* 回滚一个事务
* @return bool 成功时返回true,或者在失败时返回false
Expand All @@ -175,19 +155,14 @@ public function rollBack()
return $this->masterPdo()->rollBack();
}














/**
* 返回最后插入行的自增ID
* @return string 返回ID
*/
public function lastInsertId()
{
return $this->masterPdo()->lastInsertId();
}

/**
* 预处理语句
Expand Down Expand Up @@ -218,4 +193,28 @@ public function schema()
}
return $this->_schema;
}
















/**
* 创建查询构造器
* @return Query
*/
public function createQuery()
{
return new Query($this);
}
}
6 changes: 3 additions & 3 deletions kernel/db/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public function getSql($raw = false, &$params = [])
}

if ($params_num) {
ksort($params_num, SORT_NUMERIC);
$sql = preg_replace_callback('/\?/', function ($matches) use (&$params_num) {
return $params_num ? array_shift($params_num) : $matches[0];
$sql = preg_replace_callback('/\?/', function ($matches) use (&$params_num, &$i) {
$i++;
return isset($params_num[$i]) ? $params_num[$i] : $matches[0];
}, $sql);
}
}
Expand Down
14 changes: 14 additions & 0 deletions web/test.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<?php






$dsn = 'mysql:host=121.196.204.163;dbname=lying;charset=utf8';
$user = 'root';
$pass = 'Suyaqi1992#';

$pdo = new \PDO($dsn, $user, $pass);

$statement = $pdo->prepare('insert into user (id,username) values (10,"testname1")');
$statement->execute();

echo $pdo->lastInsertId('username');

0 comments on commit 104bb13

Please sign in to comment.