我在这里有一个名为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中的内容。我正在尝试检查是否有任何记录设置来进行会话。
答案 0 :(得分:0)
如果您只想查看$ rs的输出,那么您可以将print_r或var_dump用于相同的
echo "<pre>";
print_r($rs);
echo "</pre>";
OR
var_dump($rs);
答案 1 :(得分:-1)
如果您想要检查输入参数是否有任何行,您可以轻松编写这样的查询。
$query = "COUNT(*) user_count FROM l_user WHERE userID = ? AND password = ?";