topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 8:02 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: SQlite + Php 5.2.9 + Apache2.2  (Read 6111 times)

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
SQlite + Php 5.2.9 + Apache2.2
« on: July 19, 2009, 09:20 PM »
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

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: SQlite + Php 5.2.9 + Apache2.2
« Reply #1 on: July 20, 2009, 04:43 AM »
Should be supported - why aren't you including closing paren though?
- carpe noctem

steeladept

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,061
    • View Profile
    • Donate to Member
Re: SQlite + Php 5.2.9 + Apache2.2
« Reply #2 on: July 20, 2009, 01:19 PM »
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

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: SQlite + Php 5.2.9 + Apache2.2
« Reply #3 on: July 21, 2009, 01:21 AM »
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)));

« Last Edit: July 21, 2009, 01:27 AM by Davidtheo »

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: SQlite + Php 5.2.9 + Apache2.2
« Reply #4 on: July 21, 2009, 01:24 AM »

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


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)

Davidtheo

  • Participant
  • Joined in 2008
  • *
  • Posts: 119
    • View Profile
    • Donate to Member
Re: SQlite + Php 5.2.9 + Apache2.2
« Reply #5 on: July 21, 2009, 01:25 AM »
please help