Yekta Said Can

bawltherapistSoftware and s/w Development

Dec 13, 2013 (3 years and 8 months ago)

87 views

Burak Bozan

Yekta
Said

Can

Heysem Kaya



SQLite

is a in
-
process library that implements
a self
-
contained,

serverless
, zero
-
configuration, transactional SQL database
engine
.


SQLite

is an embedded SQL database engine.



It

does not have a separate server process.


S
QLite

reads and writes directly to ordinary disk
files
.


For

download

and

documentation

see

http://www.
sqlite
.org


Wamp Server Package includes


Apache 2.2.21,


Php 5.3.10,


Mysql 5.5.20,


PhpMyadmin 3.4.10.1,


Xdebug 2.1.2, XDC 1.5, SQLBuddy 1.3.3, webGrind 1.0


http://www.
wampserver
.com/en/


Eclipse

PHP
or

NetBeans

or

another

IDE


For

Ado
.Net API
Check
:
http
://sourceforge.net/projects/sqlite
-
dotnet2/files/SQLite%20for%20ADO.NET%202.0/
1.0.66.0/



WampServer

is a
Windows

web development
environment

that
allows
people

to create web
applications with
Apache
2 server
, PHP
and a
MySQL
(or SQLite)

database.


WampServer provides a connection between
the server (Apache), PHP, and the database
(MySQL, SQLite).


Install the latest version of WampServer


Set the default workspace of your IDE as:


C:
\
wamp
\
www
\


Open the file ‘php.ini’ in the directory


C:
\
wamp
\
bin
\
apache
\
Apache2.2.21
\
bin
\


Find
the

lines

‘;
extension
=
php
_
sqlite
.
dll

and


extension
=
php
_sqlite3.
dll



Remove the ‘;’ at the beginning of
the

lines


sqlite_open
($filename, $mode,
$
error_message
)


Opens a SQLite database and create the database if
it does not exist


Parameters


The filename of the SQLite database. If the file does
not exist, SQLite will attempt to create it


The mode of the file
[optional]


error_message

string[optional]


Example PHP line

$myDatabase
= sqlite_open
(‘friendsDatabase.sqlite
',
0666, $error);



sqlite_exec
(
$dbhandle,
$query, $
error_msg
)


Executes a result
-
less query against a given
database


Parameters:


$dbhandle: The database handle resource (
returned from
sqlite_open

when used procedurally
)

where the query will
be executed.


$
query
:
The query
string
to be executed.


$
error_msg
:
error message
string[optional]


Example PHP code segment

$
myS
t
atement

= "INSERT INTO Friends VALUES(1,'Jane
')";

$executeQuery
= sqlite_exec
($myDatabase
,
$myStatement,
$error
);


sqlite
_
close
(
$dbhandle
)


Closes an open SQLite database


Parameters:


$dbhandle: t
he SQLite
d
atabase

resource; returned
from
sqlite_open

when used procedurally.


Example PHP line

sqlite_close
($myDatabase
);


create

table

course

(
code

varchar
(10)
primary

key
,
cname

varchar
(50));



create

table

student
(
sid

integer

primary

key
,
sname

varchar
(50),
bdate

date
,
gpa

real
);



create

table

take
_
course
(
ccode

varchar
(10)
references

course

(
code
) on
delete

restrict

on
update

cascade
,
sid

integer

references

student

(
sid
) on
delete

restrict

on
update

cascade
, sem
integer
);


insert
into

student

(
sname
,
bdate

,
gpa
)
values

('Mehmet
Yilmaz
','1990
-
12
-
12',3.56);


insert
into

student

(
sname
,
bdate

,
gpa
)
values

('Deniz Kus','1989
-
02
-
09',3.90);


insert
into

student

(
sname
,
bdate

,
gpa
)
values

('Merve Kara','1988
-
01
-
19',2.50);


insert
into

course

values

('CE321','
Introduction

to

Database

systems
');


insert
into

course

values

('CE322','
Operating

Systems
');


insert
into

course

values

('CE350','
Automata

Theory
');


insert into
take_course

values ('CE322',1,2010);


insert into
take_course

values ('CE322',2,2010);


insert into
take_course

values ('CE321',1,2011);


insert into
take_course

values ('CE321',2,2011);


insert into
take_course

values ('CE321',3,2012);


insert into
take_course

values ('CE321',1,2012);


SELECT (
strftime
('%s','
now
')
-
strftime
('%s',
bdate
))/(365*24*3600) as
years

from

student
;


Select

*
from

take
_
course

where

sid
=1;



Select

count
(*)
from

take
_
course

where

ccode
='CE321'
and

sem=2011;



Select

avg
(
gpa
)
from

take
_
course

tc

inner

join

student

s on
tc
.
sid
= s.
sid

where

tc
.
ccode
='CE321'
and

tc
.sem=2011;



Select

s.
sname
,s.
gpa

from

take
_
course

tc

inner

join

student

s on
tc
.
sid
= s.
sid

where

tc
.
ccode
='CE321'
and

tc
.sem=2011;