Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGali Kulakovsky
2,059 Pointsmy film table is not recognized by compiler and I get the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such table: film' in /home/treehouse/workspace/index.php:8 Stack trace: #0 /home/treehouse/workspace/index.php(8): PDO->query('select * from f...') #1 {main} thrown in /home/treehouse/workspace/index.php on line 8
any ideas guys? )
my index.php file:
<?php
require_once('database.php');
//remove before flight
ini_set('display_errors', 'On');
$results = $db->query('select * from film');
var_dump($results);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Data Objects</title>
<link rel="stylesheet" href="style.css">
</head>
<body id="home">
<h1>Sakila Sample Database</h1>
<h2>Films by Title</h2>
<ol>
<li><i class="lens"></i>Film One</li>
<li><i class="lens"></i>Film Two</li>
<li><i class="lens"></i>Film Three</li>
<li><i class="lens"></i>Film Four</li>
</ol>
</body>
</html>
my database.php file:
<?php
try {
$db = new PDO('sqlite:./database.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
echo $e->getMessage();
die();
}
4 Answers
Kevin Korte
28,149 PointsUsually, a table name is plural, as it holds many instances of a type of data. So by chance it shouldn't be selecting all from the films table instead?
thomascawthorn
22,986 PointsHave you created the tables? You should be able to view all of your created tables with the following command. Throw it in at the top of your script and see what you get back:
<?php
$results = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'");
var_dump($results);
exit;
Gali Kulakovsky
2,059 PointsFirst of all thank you for your response!
Have I Created tables? Aren't they suppose to be there already? Have I missed a video where it is shown how to create the tables? I assumed that these tables were suppose to be there with that database.db file that comes on loading the platform from that video . Am I wrong? Anyways your example returns : object(PDOStatement)#2 (1) { ["queryString"]=> string(51) "SELECT name FROM sqlite_master WHERE type = 'table'" } and on $results = $results->fetchAll(); returns array (0) { }
seems like there are no tables there...
Leonardo Vidal
14,603 PointsWhat happen if you try to get the result from film in the console?
first write: <p>sqlite3 database.db</p>
press enter
,then: <p> select * from film; </p>
Gali Kulakovsky
2,059 PointsThanks for trying to help Leonardo.
Running your example returns nothing, three dots like that: ...>
stef2
11,393 PointsI can't seem to access database.db - had errors on the first video using the console and basically this whole course is now not fit for purpose.
Gali Kulakovsky
2,059 PointsGali Kulakovsky
2,059 Pointstried that and some other table names (in plural too), no luck... same error all the time. First I did exactly how it is shown in the video... should work but it doesn't.