Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何访问$rs值以检查它是否返回任何内容?_Php_Sqlite - Fatal编程技术网

Php 如何访问$rs值以检查它是否返回任何内容?

Php 如何访问$rs值以检查它是否返回任何内容?,php,sqlite,Php,Sqlite,这里有一个名为recordSet.class.php的类php文件 abstract class R_RecordSet { protected $db; protected $stmt; function __construct() { $this->db = pdoDB:: getConnection(); } function getRecordSet($sql, $params = null) { if (is_array($params)) {

这里有一个名为recordSet.class.php的类php文件

abstract class R_RecordSet {
protected $db;
protected $stmt;

function __construct() {
    $this->db = pdoDB:: getConnection();
}
    function getRecordSet($sql, $params = null) {
        if (is_array($params)) {
            $this->stmt = $this->db->prepare($sql);
            // execute the statement passing in the named placeholder and the value it'll have
            $this->stmt->execute($params);
        }
        else {
            $this->stmt = $this->db->query($sql);
        }
        return $this->stmt;
    }
}
class JSONRecordSet extends R_RecordSet {
    function getRecordSet($sql, $elementName = "ResultSet", $params = null) {
        $stmt     = parent::getRecordSet($sql, $params);
        $recordSet = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $nRecords = count($recordSet);
        if ($nRecords == 0) {
            $status = 'error';
            $message = json_encode(array("text" => "No records found"));
            $result = '[]';
        }
        else {
            $status = 'ok';
            $message = json_encode(array("text" => ""));
            $result = json_encode($recordSet);
        }
        //return "{\"status\": \"$status\", \"message\":$message, \"$elementName\" :{\"RowCount\": $nRecords ,\"Result\": $result}}";
        //these RowCount and results matters in service.js
        return "{\"RowCount\": $nRecords ,\"results\": $result}";
    }
}
所以当我从其他地方调用getRecordSet()时,比如:

        $loginSQL = "SELECT * FROM l_user WHERE userID='".$userid."' AND password='".$password."'";
        echo $rs->getRecordSet($loginSQL, 'ResultSet');
如何检查此变量$rs的访问权限?sqlite用于在此处检索数据。
我不熟悉PHP,也不知道如何查看$rs中的内容。我正在尝试检查是否有任何记录集用于创建会话。

如果您只想查看$rs的输出,则可以打印或转储相同的变量

echo "<pre>";
print_r($rs);
echo "</pre>";

如果希望检查输入参数是否有行,可以轻松编写如下查询


您可以
var\u dump($rs)
但是我不认为这是你想要的,我宁愿检查这个$rs在另一个php文件中是否返回0(意味着$status是no或ok)。我不知道如何检查它。您的代码容易受到SQL注入攻击,因为您没有正确使用准备好的语句。您需要访问,而不是连接它们。我希望以某种方式访问这个getRecordFunction()中的$status。
var_dump($rs);
$query = "COUNT(*) user_count FROM l_user WHERE userID = ? AND password = ?";