[英]Remove db $conn from MYSQLI query
I'm currently learning mysqli and systematically replacing all of my deprecated queries throughout my script. 我目前正在学习mysqli,并在整个脚本中系统地替换所有不赞成使用的查询。
I have this query: 我有这个查询:
<?php
$link = mysqli_connect("host", "user", "pass", "name");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT * FROM pins WHERE id='$pinDetails->id'";
$result = mysqli_query($link, $query);
/* associative array */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$feature = $row['featured'];
/* free result set */
mysqli_free_result($result);
/* close connection */
mysqli_close($link);
?>
Which I can echo throughout the page as <?php echo $row['date_featured']; ?>
我可以在整个页面中以
<?php echo $row['date_featured']; ?>
<?php echo $row['date_featured']; ?>
My question is how do I rework the code to remove the connection? 我的问题是如何重新编写代码以删除连接? I don't want to keep connecting to the db in every query when I have a general connection include at the top of the page.
当页面顶部包含常规连接时,我不想在每个查询中都保持连接到数据库。
实际上,此页面需要连接才能基于SQL数据库进行操作,您能否进一步解释一下,删除连接意味着什么,您可以使用INCLUDE();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.