我在php中调用数据库中的数据,并使用Webservices将数据传递给代号.如果我将我的URL指向JSON文件,我能够获取我的记录,但当我将其更改为php并使用JSON对页面进行编码时,我将变为null.
在Codename中使用Webservices时如何解决null结果?
这是我用代码名称调用的PHP代码
<?php
/* require the user as the parameter */
//http://localhost:8080/sample1/webservice1.php?user=1
if(isset($_GET['user']) && intval($_GET['user'])) {
/*soak in the passed variable or set our own*/
//$number_of_posts = isset($_GET['num']) ? intval($_GET['num']) : 10; //10 is the default
$format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default
//$user_id = intval($_GET['user']); //no default
/* connect to the db */
$link = mysql_connect('localhost','root','') or die('Cannot connect to the DB');
mysql_select_db('test',$link) or die('Cannot select the DB');
/* grab the posts …Run Code Online (Sandbox Code Playgroud)