我正在使用适用于PHP的Laravel 4框架制作REST API,它将更新数据库中的指定值。
我能够获取用户指定的值并更新MySQL数据库中的值(这是按预期工作)。但是,一旦完成更新,API应该将true / false返回给客户端。我该怎么做呢 ?
public function store()
{
//
$username = $_POST['username'];
$statname = $_POST['statname'];
$statvalue = $_POST['statvalue'];
//check to see if user has actually entered username = xyx, statname = xyz, statvalue = xyz
//check to see if username exists and valid statname - count of rows should be 1
//statvalue should be integer
$con = mysql_connect('localhost:8888', 'root', 'root');
mysql_select_db('DiamondHunt');
$sql = 'UPDATE UserInfo SET ' . $statname . '=' . $statvalue . ' WHERE username=\'' . $username . '\'' ;
$execute_sql = mysql_query($sql);
//return $execute_sql;
}
要测试后端,我使用curl命令(通过Mac终端)
curl -F username=ghost -F statname=kills -F statvalue=18 http://localhost:8888/l4/public/api/v1/sendStat
在后端,当我使用行echo $execute_sql;
时,它打印值1(并按预期更新数据库)。但是当我尝试使用return $execute_sql;
时,它会失败。
答案 0 :(得分:0)
如果您使用的是Laravel 4,为什么不使用fluent或eloquent ORM (除了mysql_*
已暂时弃用一段时间......)
如果您正在尝试创建REST API,为什么不使用laravel 4的RESTFUL Controllers代替..
你的生活会变得更轻松..