P. 1
SQLITE Php Pdo Referance

SQLITE Php Pdo Referance

|Views: 797|Likes:
Published by jwzumwalt
SQLite Reference - Using PHP & PDO
SQLite Reference - Using PHP & PDO

More info:

Published by: jwzumwalt on Mar 02, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/26/2015

pdf

text

original

If we need to check and see if the table exists, here is an enhanced version.

/* Listing 8.2 - Check if table exists */
echo '';
echo '

Check if table exist

';

... code to connect to database, and handle errors

#check master table for table name
$query ="SELECT name FROMsqlite_master WHERE type='table' and name='table_to_make'";

ZoomAviation.com ‐ by Jan Zumwalt                                                                                                         Revised   August 25, 2015
SqLite Reference                                                                                                                                                 Copyright © 2005‐2015

Pg 24 of 84

$db->query("$query") or die(" Error adding table: $query");
$totaltables =sqlite_num_rows($query);

#does table exist
if ($totaltables<1) {
# table does not exist, create table
$query ="CREATE TABLE test (
id INTEGER PRIMARY KEY,
col1name TEXT(25),
col2name TEXT(25) )";

}
else{
#table exists...don't create again , do something else
}
. . . programcontinues

Listing: 4.2 – Check if table exists

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->