我的mysql表如下;
CREATE TABLE IF NOT EXISTS `cheque_data` (
`auto_no` int(11) NOT NULL AUTO_INCREMENT,
`job_no` int(11) NOT NULL,
`client_id` text NOT NULL,
`ch_no` text NOT NULL,
`ch_date` date NOT NULL,
`ch_bank` text NOT NULL,
`ch_amount` decimal(10,2) NOT NULL,
`sync` int(1) NOT NULL DEFAULT '0',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`auto_no`)
)
当我在 PHPMYADMIN 中运行 SQL 命令时,它将检索行;
SELECT * FROM `cheque_data` WHERE timestamp='2014-03-10 19:37:31'.
但是在 PHP 中,
$sql = "select * from `cheque_data` where timestamp = '2014-03-10 19:37:31'";
$result_remote = mysqli_query($con,$sql) or die(mysqli_error($con));
$row_count = mysqli_num_rows($result_remote);
echo $row_count; //no data
它没有提供任何数据。但是当我将时间戳更改为其他列时,它就起作用了。
$sql = "select * from `cheque_data` where auto_no = '1'";
$result_remote = mysqli_query($con,$sql) or die(mysqli_error($con));
$row_count = mysqli_num_rows($result_remote);
echo $row_count; //data found
我想知道这个问题的原因是什么? 它只是不适用于时间戳
谢谢你, 萨梅拉
最佳答案
在时间戳字段周围添加反引号(`),因为它是保留字或使用此查询
$sql = "select * from `cheque_data` where `timestamp` = '2014-03-10 19:37:31'";
关于php - MYSQL选择不检索时间戳数据的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22322092/