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

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

WBOY
WBOYOriginal
2016-06-06 20:26:361315browse

我在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>

回复内容:

我在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>

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>

推荐使用pdo

Statement:
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