[英]mysqli prepared statement bind result and loop
I have this code in purpose to search in the database : 我有此代码旨在在数据库中进行搜索:
$key = '%'.$_GET['key'].'%';
$result= $db->prepare("SELECT * FROM information WHERE stuId LIKE ?
OR stuName LIKE ? LIMIT ?,10");
$result->bind_param('ssi',$key,$key,$startpage);
$result->execute();
$result->bind_result($stuId,$stuName,$date,$stuSex,$stuAdd);
while($result->fetch()) {
$stuDoB= $date->format('d/m/Y');
echo "<tr>
<td class='col1'>
<div>$stuId</div>
</td>
<td>
<div><a href='editStudent.php?stuId=$stuId'>" . htmlspecialchars($stuName) . "</a></div>
</td>
<td class='col3'>
<div>$stuDoB</div>
</td>
<td class='col4'>
<div>$stuSex</div>
</td>
<td class='col5'>
<div>" . htmlspecialchars($stuAdd) . "</div>
</td>
</tr>";
}
Im trying to learn prepared statement, so I change from normal way to above code Could you tell me : 我正在尝试学习准备好的语句,因此我从正常方式更改为上述代码,您能告诉我:
$result->fetch()
or just 1 time bind_result()
outside the loop? $result->fetch()
result- $result->fetch()
内bind_result()
还是在循环外仅bind_result()
一次bind_result()
? Fatal error: Call to a member function format() on a non-object in D:\\xampp\\htdocs\\baiTapLon\\showPage.php on line 30
Fatal error: Call to a member function format() on a non-object in D:\\xampp\\htdocs\\baiTapLon\\showPage.php on line 30
Line 30 is $stuDoB= $date->format('d/m/Y');
第30行是
$stuDoB= $date->format('d/m/Y');
Please help me out. 请帮帮我。
You have to use bind_result
once means outside the loop 您必须在循环外使用一次手段
bind_result
You can't use format for any variable use it like this 您不能将格式用于任何变量 ,像这样使用它
$date1 = new DateTime($date);
$stuDoB= $date1->format('d/m/Y');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.