试图用php制作json文件时出错

时间:2017-10-02 11:11:25

标签: php mysql json

这是我的代码(我的目标:用php制作json文件):

<?php $conn = mysql_connect("localhost","root","","andtt");
if (!$conn) {
    die("Connection failed: " . mysql_connect_error());
}
echo "Connected successfully"; 
$sql="select * from posts limit 20";
$response = array();
$posts = array();
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$title=$row['title'];
$url=$row['url'];
$posts[] = array('title'=> $title, 'url'=> $url);
}
$response['posts'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
?> 

我在这一行得到了一个错误:

while($row=mysql_fetch_array($result))
  

警告:mysql_fetch_array()期望参数1是资源,   在C:\ wamp \ www \ landing \ dms \ post.php

中给出的布尔值

the error image

有人可以告诉我为什么会收到此错误吗?

0 个答案:

没有答案