简体   繁体   English

SQL中始终为NULL返回值

[英]Always NULL return value in SQL

I have the following SQL function, and I have delare the $row in the mysqli_stmt_bind_result. 我具有以下SQL函数,并且在mysqli_stmt_bind_result中删除了$ row。

//get the user number per month
public function chartwaitinguservsproduct(){
    $stmt = mysqli_prepare($this->connection, 
            "select 
                (Select COUNT(*)  from reusematching.waitinglist_product) as COUNTP,
                (Select COUNT(*)  from reusematching.waitinglist_user) as COUNTU;
                ");     
    $this->throwExceptionOnError();

    mysqli_stmt_execute($stmt);
    $this->throwExceptionOnError();

    mysqli_stmt_fetch($stmt);
    mysqli_stmt_bind_result($stmt, $row->COUNTP, $row->COUNTU);


    mysqli_stmt_free_result($stmt);
    mysqli_close($this->connection);

    return $rows;

}

but not matter how I change the Database, the $rows always NULL. 但无论如何更改数据库,$ rows始终为NULL。 Why? 为什么? because of the fetch statement?? 因为获取语句?

Why are you using $row in one place (the bind) and returning $rows ? 为什么在一个位置(绑定)中使用$row并返回$rows

Don't you think that might be a bad idea, unless your PHP interpreter is far more advanced than the ones I've seen, and able to automatically associate singular and plural variable names :-) 难道你不认为这可能是一个坏主意,除非你的PHP解释器是远远比我见过的那些更先进,并能够单数和复数变量名:-)自动关联

And, from memory, I think you should probably bind the variables before trying to fetch from them. 而且,从内存来看,我认为您可能应该尝试绑定变量, 然后再尝试从中获取变量。 Again, if your PHP is advanced enough, I suppose it could do some form of temporal manipulation, but I wouldn't bet money on it. 再说一次,如果您的PHP足够高级,我想它可以进行某种形式的时间操纵,但是我不会赌钱。


Sorry, that's the Australian humour coming through but if you examine the fetch page , it states quite clearly: 抱歉,这是澳大利亚的幽默,但是如果您查看提取页面 ,它会非常清楚地表明:

Note that all columns must be bound by the application before calling mysqli_stmt_fetch(). 请注意,在调用mysqli_stmt_fetch()之前,所有列都必须由应用程序绑定。

I'll assume for now that the row/rows issue was just a typo in your question. 我现在假设row/rows问题只是您问题中的错字。 If it wasn't, then that will need fixing as well. 如果不是,那也需要修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM