Sunday, September 28, 2008

SPR720 Lab, compile and run SQLite


Our Lab involved getting the source for something interesting and compiling and using it. It was fun to do: there were no dependencies issues and all went well. I had trouble trying to talk sql with it though but the prof had it working properly in a minute. I'll experiment with it a bit as I want to put some practice web db stuff on my matrix account. Good fun!

sqlite> CREATE TABLE `symbols` (
...> `id` int(11),
...> `country` varchar(255) NOT NULL default '',
...> `animal` varchar(255) NOT NULL default '');
sqlite> INSERT INTO `symbols` VALUES (1, 'America', 'eagle');
sqlite> INSERT INTO `symbols` VALUES (2, 'China', 'dragon');
sqlite> INSERT INTO `symbols` VALUES (3, 'England', 'lion');
sqlite> INSERT INTO `symbols` VALUES (4, 'India', 'tiger');
sqlite> INSERT INTO `symbols` VALUES (5, 'Australia', 'kangaroo');
sqlite> INSERT INTO `symbols` VALUES (6, 'Norway', 'elk');
sqlite> select * from symbole;
SQL error: no such table: symbole
sqlite> select * from symbols;
1|America|eagle
2|China|dragon
3|England|lion
4|India|tiger
5|Australia|kangaroo
6|Norway|elk
sqlite>


Figure out how to change these connect and select statements to sqlite this will be useful
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM $symbols";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

No comments: