簡體   English   中英

如何訪問$ rs值以檢查其是否返回任何內容?

[英]How can I access to $rs value to check if it returns anything?

我在這里有一個名為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的輸出,則可以使用相同的print_r或var_dump

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

要么

var_dump($rs);

如果您要檢查輸入的參數是否存在任何行,則可以輕松編寫這樣的查詢。

$query = "COUNT(*) user_count FROM l_user WHERE userID = ? AND password = ?";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM