ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

SQlite + Php 5.2.9 + Apache2.2

(1/2) > >>

Davidtheo:
Can someone please help me with sqlite.

I am using SQlite + Php 5.2.9 + Apache2.2.

I can create a table using "CREATE TABLE startup (row_id INTEGER PRIMARY KEY"

But when I try to use "CREATE TABLE startup IF NOT EXISTS (row_id INTEGER PRIMARY KEY" or "CREATE TABLE IF NOT EXISTS startup (row_id INTEGER PRIMARY KEY" I am getting this error.

"Error in query: SQL logic error or missing database"

Does anyone know if the "IF NOT EXISTS" statement can be used with SQlite, Php 5.2.9 + Apache2.2. or is there an other way of checking if a table does exists before trying to create it.

f0dder:
Should be supported - why aren't you including closing paren though?

steeladept:
There does not seem to be a database created yet to put tables into.  Shouldn't there be an "...) IN DATABASE"  added to the end?

If it doesn't exist yet, perhaps a CREATE DATABASE DEVDB where DEVDB is the name of the database...

Or am I way off here?  I am going from my SQL knowledge, not any particular program.

Davidtheo:
Everywhere I have looked says it is supported and it works without the "IF NOT EXISTS".

There is the rest of the code - some columns I am using the try catch in replace of the "IF NOT EXISTS"  :-[ and it works without the "IF NOT EXISTS"


--- ---$mysql = "CREATE TABLE startup (row_id INTEGER PRIMARY KEY, ";
$mysql .= "games TEXT NOT NULL, ";
$mysql .= "user_id TEXT NOT NULL, ";
.
.
.
.
$mysql .= "age TEXT ";
.
.
$mysql .= "); ";

if ($db = sqlite_open('jx3.db', 0666, $sqliteerror)) {
//catch if database is already there
try{
sqlite_query($db,$mysql);
} catch(Exception $e){

}

$mysql = "INSERT INTO startup (games,user_id,age";
.
.
.
.
$mysql .= ") VALUES (\"";
$mysql .= $var_games . "\",\"" .$var_id . "\",\"";
.
.
.
.
$mysql .= $var_age . "\")";

sqlite_query($db, $mysql) or die("Error in query: ".sqlite_error_string(sqlite_last_error($db)));

But when I use the "IF NOT EXISTS" it gives me a error  :( :( I do not understand why??


--- ---$mysql = "CREATE TABLE IF NOT EXISTS startup (row_id INTEGER PRIMARY KEY, ";
$mysql .= "games TEXT NOT NULL, ";
$mysql .= "user_id TEXT NOT NULL, ";
.
.
.
.
$mysql .= "age TEXT ";
.
.
$mysql .= "); ";

if ($db = sqlite_open('jx3.db', 0666, $sqliteerror)) {

sqlite_query($db,$mysql);

$mysql = "INSERT INTO startup (games,user_id,age";
.
.
.
.
$mysql .= ") VALUES (\"";
$mysql .= $var_games . "\",\"" .$var_id . "\",\"";
.
.
.
.
$mysql .= $var_age . "\")";

sqlite_query($db, $mysql) or die("Error in query: ".sqlite_error_string(sqlite_last_error($db)));

Davidtheo:

If it doesn't exist yet, perhaps a CREATE DATABASE DEVDB where DEVDB is the name of the database...

-steeladept (July 20, 2009, 01:19 PM)
--- End quote ---

With this line if the DB file does not exist it will create and open it. If it does exist it will open it.

sqlite_open('jx3.db', 0666, $sqliteerror)

Navigation

[0] Message Index

[#] Next page

Go to full version