FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add support for parameterized SQL queries#2 · internet-dev/framework@6529d8b · GitHub

Repository navigation

Commit 6529d8b

Browse files
committed
add support for parameterized SQL queries#2
1 parent 5708f64 commit 6529d8b

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

‎libs/Swoole/Database/PdoDB.php‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,80 @@ public final function query($sql)
5555
);
5656
return $res;
5757
}
58+
59+
/**
60+
* 执行一个参数化SQL语句,并返回一行结果
61+
* @param string $sql 执行的SQL语句
62+
* @param mixed $_ [optional]
63+
* @return mixed
64+
*/
65+
public final function queryLine($sql, $_)
66+
{
67+
$params = func_get_args();
68+
if ($this->debug)
69+
{
70+
var_dump($params);
71+
}
72+
array_shift($params);
73+
$stm = $this->prepare($sql);
74+
if ($stm->execute($params))
75+
{
76+
$ret = $stm->fetch();
77+
$stm->closeCursor();
78+
return $ret;
79+
} else {
80+
\Swoole\Error::info("SQL Error", implode(", ", $this->errorInfo()) . "<hr />$sql");
81+
}
82+
}
83+
84+
/**
85+
* 执行一个参数化SQL语句,并返回所有结果
86+
* @param string $sql 执行的SQL语句
87+
* @param mixed $_ [optional]
88+
* @return mixed
89+
*/
90+
public final function queryAll($sql, $_)
91+
{
92+
$params = func_get_args();
93+
if ($this->debug)
94+
{
95+
var_dump($params);
96+
}
97+
array_shift($params);
98+
$stm = $this->prepare($sql);
99+
if ($stm->execute($params))
100+
{
101+
$ret = $stm->fetchAll();
102+
$stm->closeCursor();
103+
return $ret;
104+
} else {
105+
\Swoole\Error::info("SQL Error", implode(", ", $this->errorInfo()) . "<hr />$sql");
106+
}
107+
}
108+
109+
/**
110+
* 执行一个参数化SQL语句
111+
* @param string $sql 执行的SQL语句
112+
* @param mixed $_ [optional]
113+
* @return int last insert id
114+
*/
115+
public final function exec($sql, $_)
116+
{
117+
$params = func_get_args();
118+
if ($this->debug)
119+
{
120+
var_dump($params);
121+
}
122+
array_shift($params);
123+
$stm = $this->prepare($sql);
124+
if ($stm->execute($params))
125+
{
126+
return $this->lastInsertId();
127+
} else {
128+
\Swoole\Error::info("SQL Error", implode(", ", $this->errorInfo()) . "<hr />$sql");
129+
}
130+
}
131+
58132
/**
59133
* 关闭连接,释放资源
60134
* @return null

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL