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 trial

PHP PHP & Databases with PDO Getting Started With PDO Introductions

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Console doesn't work with sqLite3

Console does't work

My version of the console as of now is

treehouse:~/workspace$ sqlite3                                                        
SQLite version 3.7.17 2013-05-20 00:56:22                                    

But the video's version is

```treehouse:~/workspace$ sqlite3 SQLite version 3.8.2 2013-12-04 14:53:30

Which seems to me to suggest that workspaces has reverted back to an earlier version which is not compatable with the suggested commands.

I can get into ```sqlite3``` by typing the command


But as soon as I try to open a database ```sqlite3 database.db``` I get locked in and no other commands will work.


```sqlite> sqlite3 database.db                                                           
   ...>                                                                               

Help! :-)

very frustrating . .

3 Answers

I see , normally after using the sqlite3 command in the console

sqlite3 

After the sqlite3 console prompt shows up

sqlite >

you can not us sqlite3 database command . Since there is no comand name sqlite3 in the sqlite3 commands.

Instead from the from the workspaces console prompt type in sqlite3 followed by the database name you want to target.

If its not already there, it will be created.

I would also delete all databases in the workspaces and make a new fresh copy/import of the database.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Thank you Shadrack. It seems to be working now.

I'm sure in Hampton;s version he was able to link the databases from inside of sqlite so i was following that setup rigidly. But I was able to get around by following your advice, so thanks for that :)

Glad to help, Happy coding.

To start using sqlite3 make sure you type sqlite3 database.db in a blank workspace like:

treehouse:~/workspace$ sqlite3 database.db

That is; if you are already using in sqlit3 , to open database.db use .open command

treehouse:~/workspace$ sqlite3                                             
. . .
sqlite> .open database.db

You can also just exit using .exit command to exit and open the database afresh.

.exit

Then go ahead and open the database

 sqlite3 database.db

You can now use "SQL" commands to create tables, manipulate data, and so on.

You can also use sqlite3 dot commands commands like:

.databases  

will list all databases

.tables 

will show all tables in the database

.help 

to see more other sqlite3 commands.

NOTE: not all dot commands are available in the open database, since each command may have a particular context in which to function.

See Sqlite3 commanline official documentation

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Thanks Shadrock, but it doesn't work.

The .open command is deprecated on my console and it locks out as soon as I try

sqlite3 database.db

Thanks !!

I see, I cant use the .open command either . In stead I used sqlite3 database.db, if you are using the same version then you will be ok. Here is what workspaces output tooks like.

sqlite3 database.db then .databases command

treehouse:~/workspace$ sqlite3 database.db                                                         
SQLite version 3.7.17 2013-05-20 00:56:22                                                          
Enter ".help" for instructions                                                                     
Enter SQL statements terminated with a ";"                                                         
sqlite> .databases       

resulting output , shows the database :

seq  name             file                                                                         
---  ---------------  ----------------------------------------------------------                   
0    main             /home/treehouse/workspace/database.db  

.table command

sqlite> .tables

Outputs all the tables in the database.

address                 film_actor              rental                                             
category                film_category           sales_by_film_category                             
city                    film_list               sales_by_store                                     
country                 film_text               staff                                              
customer                inventory               staff_list                                         
customer_list           language                store                                              
film                    payment  

SQL command, terminated by semicolon ";"

sqlite> SELECT * FROM city;           

Output All elements in city table

1|A Corua (La Corua)|87|2015-01-08 14:08:08                                                        
2|Abha|82|2015-01-08 14:08:08                                                                      
3|Abu Dhabi|101|2015-01-08 14:08:08                                                                
4|Acua|60|2015-01-08 14:08:08                                                                      
5|Adana|97|2015-01-08 14:08:08                                                                     
6|Addis Abeba|31|2015-01-08 14:08:08                                                               
7|Aden|107|2015-01-08 14:08:08                                                                     
8|Adoni|44|2015-01-08 14:08:08                                                                     
9|Ahmadnagar|44|2015-01-08 14:08:08                                                                
10|Akishima|50|2015-01-08 14:08:08                                                                 
11|Akron|103|2015-01-08 14:08:08 
. . .      all element in city table ...

It works perfectly.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

That's part of the problem. We're using different versions of Workspaces to the video. Does anyone know of a way to use a different Workspaces version? :-)

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

This is how my console looks. As you can see it also gives the Workspaces version and the commands I've tried to use.

Path to Workspaces