|
发表于 2016-5-23 17:09:33
|
显示全部楼层
CI并没有使用预编译机制。
- $mysqli = new mysqli("localhost", "root", "root", 'demo');
- //使用问号替代变量位置
- $sql = "SELECT uid,username FROM user WHERE username=?";
- $stmt = $mysqli->prepare($sql);
- //绑定变量
- $stmt->bind_param("s", $username);
- $stmt->execute();
- $stmt->bind_result($uid, $username);
- while ($stmt->fetch()) {
- $row = array();
- $row['uid'] = $uid;
- $row['username'] = $username;
- $userinfo[] = $row;
- }
复制代码
CI使用的过滤方式是使用原生的过滤方法:
- protected function _escape_str($str)
- {
- return $this->conn_id->real_escape_string($str);
- }
复制代码 |
|