现在我试图通过mysql查询将结果附加到php中的变量,这是使用的代码:
<?php
$con=mysqli_connect("localhost","root","","ezsnip");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysql_query("SELECT Snip FROM snips WHERE ID='1'");
$row = mysql_fetch_array($result);
$snip = $row['Snip'];
$snip = str_replace('<?php', '<?php', $snip);
$snip = str_replace('?>', '?>', $snip);
?>
<div id="editor"><?php echo $snip; ?></div>
当我运行代码时,它返回:mysql_fetch_array()期望参数1为资源,布局在 C:\ xampp \ htdocs \ home.php 中给出 170
第170行是:
$row = mysql_fetch_array($result);
答案 0 :(得分:0)
创建mysql_query
资源
mysqli
<?php
$con=mysqli_connect("localhost","root","","ezsnip");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT Snip FROM snips WHERE ID='1'");
$row = mysqli_fetch_array($result);
$snip = $row['Snip'];
$snip = str_replace('<?php', '<?php', $snip);
$snip = str_replace('?>', '?>', $snip);
?>
<div id="editor"><?php echo $snip; ?></div>