我的SQL语句在运行时没有输出任何内容。只是一个空屏幕。
这是我的PHP代码:
<?php
$con = mysqli_connect("localhost", "root", "root","payBills");
$paidBills = "SELECT * FROM houseBills WHERE houseID = '20'";
$resultset = mysqli_query($con, $paidBills);
$records = array();
//Loop through all our records and add them to our array
while ($r = mysqli_fetch_assoc($resultset)) {
$records[] = $r;
}
//Output the data as JSON
echo json_encode($records);
?>
这是我的SQL表
CREATE TABLE `houseBills` (
`houseBillID` int(11) NOT NULL AUTO_INCREMENT,
`houseID` varchar(11) NOT NULL,
`name` varchar(50) NOT NULL,
`amount` varchar(10) NOT NULL,
`date` varchar(50) NOT NULL,
`addedBy` varchar(100) NOT NULL,
PRIMARY KEY (`houseBillID`),
UNIQUE KEY `houseBillID` (`houseBillID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `houseBills`
--
INSERT INTO `houseBills` (`houseBillID`, `houseID`, `name`, `amount`, `date`, `addedBy`) VALUES
(1, '20', 'Loo roll', '£10', '10', 'samstone920@googlemail.com'),
(2, '20', 'toothpaste', '3', 'egreg', '44tq');
有没有明显的迹象表明我失踪了?
答案 0 :(得分:1)
表格当前设置为CHARSET = latin1 JSON_ENCODE除此之外没有。看这篇文章:json_encode is returning NULL?。 ALTER TABLE houseBills CONVERT TO CHARACTER SET utf8;
因为表格在更改之前已经包含数据,所以这仍然会产生问题。在这种情况下(测试阶段项目),解决方案是重新输入数据。对于大型现有表,或许尝试将数据复制到新表可能会提供解决方案。请注意,这是未经测试的。