SQLite INSERT
Now that you have learned how to create an SQLite table, you now would like to learn how to put things in wouldn't you?
Before we move on, you might want to make a quick detour to the SQL Injection page, as you might have a Little Bobby Tables come along one day... So, take a look and come back here...
If you know MySQL/MSSQL, you will probably already know how this works, but to those that don't know, I don't think it is that hard still.
Okay, lets say we have a SQLite Table made with this SQLite Query: [Refer to CREATE TABLE]
CREATE TABLE info (
variable TEXT,
value TEXT,
time INT(10) default '0'
);
Now here is what an SQLite INSERT might look like for the table above.
/* $con is obviously the SQLite Handle */
$time = time();
sqlite_query($con, "INSERT INTO info (variable, value, time) VALUES('site_name','NoSQL','$time')", $result_type, $query_error);
if(!empty($query_error))
echo $query_error;
else
echo "Query Successful!";
Once you get Query Successful! That means the row with the variable of site_name has a value of NoSQL, and time is set to the current 10 INT time stamp (Refer to time)
Break it down
INSERT INTO info - Should I have to explain INSERT INTO? It means it is Inserting into the table info, or table you choose.
(variable, value, time) - This defines what rows you will be setting, you can exclude the variable column, the value column, or the time column, or as many as you want, in fact, this this is optional, at least on this exact query, I will talk more about that later though.
VALUES('site_name','NoSQL','$time') - VALUES is the values you are going to set for that row, it must be in the order of what we set before (The (variable, value, time) declaration)
Simple? If you are having troubles, you can always get help in our forum
As I was saying before, the (variable, value, time) declaration is not needed, as long as you are going to set all columns of the table, you can do this:
/* $con is obviously the SQLite Handle */
$time = time();
sqlite_query($con, "INSERT INTO info VALUES('site_name','NoSQL','$time')", $result_type, $query_error);
if(!empty($query_error))
echo $query_error;
else
echo "Query Successful!";
However, I should say, I do not recommend doing this, because if you alter the table such as changing or adding a column, you may get issues, though of course you can easily fix it, just less error prone.