好吧..我已经在网上闲逛了几个小时,试图弄清楚如何转换我的旧mysql
这是我的PHP代码atm
$sql2="SELECT * FROM $tbl_name_question2 WHERE question_id='$question_id_comments' ORDER BY a_id ASC";
$result2=mysql_query($sql2);
// Comment Loop Starts
while($rows=mysql_fetch_array($result2)){
?>
<div class="row comment-body">
<div class="col-md-3">
<p><? echo $rows['a_name']; ?></p>
<span><? echo $rows['a_datetime']; ?></span>
</div>
<div class="col-md-9">
<p><? echo $rows['a_answer']; ?></p>
</div>
</div>
<?php } // Comment Loop Ends ?>
我编写了MySQLi准备好的语句以插入有效的内容时,我已经正确设置了数据库连接信息,但是我无法弄清楚这一点。
$datetime=date("m/d/y h:i"); // Format Date And Time
// Connect
$mysqli = new mysqli('private', 'private', 'private', 'private');
// Check Connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
如果有人可以向我展示校正方向或向我展示如何进行转换,那将不胜感激!
提前非常感谢!
// Prepare the statement, using ? in place of parameters
// Note that you can only use parameters where expressions are allowed, so the
// tablename must still be done by substituting a variable
$stmt = $mysqli->prepare("SELECT a_name, a_datetime, a_answer FROM $tbl_name_question2
WHERE question_id = ?
ORDER BY a_id ASC");
// Bind the parameters to the corresponding variables
$stmt->bind_param("s", $question_id_comments);
$stmt->execute();
// Bind variables to receive the results
$stmt->bind_result($name, $datetime, $answer);
// Fetch the rows, and use the above variables to output the results
while ($stmt->fetch() {
?>
<div class="row comment-body">
<div class="col-md-3">
<p><? echo $name; ?></p>
<span><? echo $datetime; ?></span>
</div>
<div class="col-md-9">
<p><? echo $answer; ?></p>
</div>
</div>
<?php }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句