Home > Backend Development > PHP Tutorial > mysqli_bind_param()已经被废弃并且将会被移除。 那现在用什么代替?

mysqli_bind_param()已经被废弃并且将会被移除。 那现在用什么代替?

WBOY
Release: 2016-06-06 20:26:36
Original
1321 people have browsed it

我在php手册看到了这句话,

mysqli_bind_param()已经被废弃并且将会被移除

那现在用什么代替了这种写法

<code><?php $username = "aaa";    
$pwd = "pwd";    
$sql = "SELECT * FROM table WHERE username = ? AND pwd = ?";    
bindParam($sql, 1, $username, 'STRING');  //以字符串的形式.在第一个问号的地方绑定$username这个变量    
bindParam($sql, 2, $pwd, 'STRING');       //以字符串的形式.在第二个问号的地方绑定$pwd这个变量    
echo $sql;    
?></code>
Copy after login
Copy after login

回复内容:

我在php手册看到了这句话,

mysqli_bind_param()已经被废弃并且将会被移除

那现在用什么代替了这种写法

<code><?php $username = "aaa";    
$pwd = "pwd";    
$sql = "SELECT * FROM table WHERE username = ? AND pwd = ?";    
bindParam($sql, 1, $username, 'STRING');  //以字符串的形式.在第一个问号的地方绑定$username这个变量    
bindParam($sql, 2, $pwd, 'STRING');       //以字符串的形式.在第二个问号的地方绑定$pwd这个变量    
echo $sql;    
?></code>
Copy after login
Copy after login

mysqli_stmt_bind_param

http://php.net/manual/zh/mysqli-stmt.bind-param.php

用pdo吧

<code class="php">$username = "aaa";    
$pwd = "pwd";    
$sql = "SELECT * FROM table WHERE username = ? AND pwd = ?";   
$sth = $dbh->prepare($sql);
$sth->bindParam(1, $username, PDO::PARAM_STR);
$sth->bindParam(2, $pwd , PDO::PARAM_STR, 12);
$sth->execute();</code>
Copy after login

推荐使用pdo

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template