我不明白为什么我的php什么都不显示。 我有一个数据库电影,我想把基地的元素放在一个JSON中。 但是,当我用我的localhost测试php时,我什么都没有。PHP MySQL Json_encode什么都不显示
我的数据库电影:
DROP TABLE IF EXISTS `Movies` ;
CREATE TABLE IF NOT EXISTS `Movies` (
`classment` INT NOT NULL,
`title` VARCHAR(45) NOT NULL,
`actors` VARCHAR(45) NOT NULL,
`kind` VARCHAR(45) NOT NULL,
`director` VARCHAR(45) CHARACTER SET 'big5' NOT NULL,
`date` DATE NOT NULL,
`image` BLOB NULL,
`summary` VARCHAR(1000) NOT NULL,
PRIMARY KEY (`classment`))
ENGINE = InnoDB;
我插入两个电影到数据库:
INSERT INTO Movies (classment, title, actors, kind, director, date, image, summary)
VALUES ('1', 'The Lord of the rings : The fellowship of the rings', 'Elijah Wood, Ian McKellen, Viggo Mortensen', 'Adventure/Fantasy', 'Peter Jackson','19/12/2001', 'LOAD_FILE("/home/michael/Documents/Dkit/Master1/Semester2/Enterprise_Mobility/CA2/images/LoR1.jpeg")', 'A meek hobbit of the Shire and eight companions set out on a journey to Mount Doom to destroy the One Ring and the dark lord Sauron.');
INSERT INTO Movies (classment, title, actors, kind, director, date, image, summary)
VALUES ('2', 'The Lord of the rings : The two towers', 'Elijah Wood, Ian McKellen, Viggo Mortensen', 'Adventure/Fantasy', 'Peter Jackson','18/12/2002', 'LOAD_FILE("/home/michael/Documents/Dkit/Master1/Semester2/Enterprise_Mobility/CA2/images/LoR2.jpeg")', 'While Frodo and Sam edge closer to Mordor with the help of the shifty Gollum, the divided fellowship makes a stand against Sauron\'s new ally, Saruman, and his hordes of Isengard.');
我的PHP代码:
<?php
try{
$handler = new PDO('mysql:host=localhost;dbname=movies', 'root', 'xxxx');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(Exception $e){
echo $e->getMessage();
die();
}
// query the application data
$query = $handler->prepare('SELECT title, image FROM Movies');
//execute the prepared statement
$query->execute();
// an array to save the application data
$rows = array();
// iterate to query result and add every rows into array
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $row;
}
$row1["ListMovies"] = $rows;
die(json_encode($row1));
?>
我想获得这样的出头: {“ListMovies”:[]}
感谢您的帮助
迈克尔
您是否可以通过将页面更改为die(“我在这里!”)来确认页面正在进入最终die()行; – 2015-03-19 11:47:39
当我改变死亡(“我是她!”);什么也没有显示。 – mickey74 2015-03-19 11:53:34
这表明问题在别处。在<?php error_reporting(E_ALL);之后,将此权限添加到脚本的开头。 ini_set('display_errors',1); – 2015-03-19 11:54:49