How to return false if 0 rows affected with PDO?

前端 未结 3 1049
走了就别回头了
走了就别回头了 2021-01-26 02:31

How can I return false if 0 rows affected with PDO?

I have this method to execute a SQL query,

public function executeSQL($query, $params = array())
{

          


        
相关标签:
3条回答
  • 2021-01-26 03:33

    Please consider

    return $stmt->rowCount() > 0;
    
    0 讨论(0)
  • 2021-01-26 03:34

    Try this

    return $stmt->rowCount() > 0;
    
    0 讨论(0)
  • 2021-01-26 03:35

    Or

    return (bool) $stmt->rowCount();
    
    0 讨论(0)
提交回复
热议问题