PHP wpdb get_var查询返回零

PHP wpdb get_var查询返回零,php,json,api,wordpress,Php,Json,Api,Wordpress,我有以下代码,它通过服务器端API向数据库添加一些数据。字段order_编号应通过$OrderNumberNext创建,该字段由count*+1作为order_num变量计算 但是,完成此操作后检查数据库表明,此操作仅计算为0。我应该为此使用不同的函数调用吗 function addChartToSet($chartId, $setId){ $chartWithId = $this->db->get_var($this->db->prepare("select

我有以下代码,它通过服务器端API向数据库添加一些数据。字段order_编号应通过$OrderNumberNext创建,该字段由count*+1作为order_num变量计算

但是,完成此操作后检查数据库表明,此操作仅计算为0。我应该为此使用不同的函数调用吗

 function addChartToSet($chartId, $setId){
     $chartWithId = $this->db->get_var($this->db->prepare("select id from chords where chord_id=%s",$chartId));
     $setWithId = $this->db->get_var($this->db->prepare("select id from sets where set_id=%s",$setId));     

     $orderNumberNext = $this->db->get_var($this->db->prepare("select count(*)+1 as `order_num` from `chords_inside_sets` where `set_id`=%s",$setId));

     $this->db->query($this->db->prepare("update sets set `last_updated_time`=NOW() where `set_id`=%s",$setId));
     $this->db->query($this->db->prepare("insert into `chords_inside_sets` set `chord_id`=%s , `set_id`=%s, `order_number`= %s",$chartWithId,$setWithId,$orderNumberNext));

     return array("last_updated_time"=>  $this->getMaxUpdatedTimeForSet($setId), "query"=>  $this->db->last_query);
 }

您正在获取数据的查询中添加1。它不能工作。首先通过SELECT查询获取您的计数,然后在下一行添加一个,如下所示:

 $orderNumberNext = $this->db->get_var($this->db->prepare("select count(*) as `order_num` from `chords_inside_sets` where `set_id`=%s",$setId));
$orderNumberNext++;

谢谢你的回复。我已经试过了,但仍然不起作用。以前它返回0,现在它在++之后返回1。另外,我尝试更改它以获取_行,然后从变量$orderNumberNext->order_num中提取order_num。这也不会产生我需要的。这里有什么想法吗?是否是PHP中的设置导致了问题?该查询在Sequel PRO中运行良好,但在代码中运行时不起作用。