Hello,
can someone help me with a simple question? (Apologies if I haven’t posted in the correct forum).
I’m creating a webpage for use on my desktop using HTML5, CSS3 and jQuery for the UI. I have a form that I want to connect to a SQLite3 database. How can I do this with PHP (I’m using ver. 5.4.45)? How do I embed the PHP code so that this utility I’m making is portable?
When I use this code in a separate file (
):
[php]<?php
class MyDB extends SQLite3
{
function __construct()
{
$this->open(‘mydb.db’);
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo “Opened database successfully\n”;
}
$sql =<<<EOF
CREATE TABLE MYTABLE
(ID INT PRIMARY KEY,
NAME TEXT,
VS VARCHAR,
VB VARCHAR,
DENIED BOOL DEFAULT n,
USING BOOL DEFAULT n);
INSERT INTO MYTABLE (ID,NAME,VS,VB,DENIED,USING)
VALUES(1,'CT','soo1','boo1','n','n');
INSERT INTO MYTABLE (ID,NAME,VS,VB,DENIED,USING)
VALUES(2,'NY','soo2','boo2','n','n');
INSERT INTO MYTABLE (ID,NAME,VS,VB,DENIED,USING)
VALUES(3,'HA','soo3','boo3','n','n');
INSERT INTO MYTABLE (ID,NAME,VS,VB,DENIED,USING)
VALUES(4,'AZ','soo4','boo4','n','n');
INSERT INTO MYTABLE (ID,NAME,VS,VB,DENIED,USING)
VALUES(5,'TS','soo5','boo5','n','n');
EOF;
$ret = $db->exec($sql);
if(!$ret){
echo $db->lastErrorMsg();
} else {
echo “Records created successfully\n”;
}
$db->close();
?>[/php]
The page shows this along the top in precisely this way:
open(‘mydb.db’); } } $db = new MyDB(); if(!$db){ echo $db->lastErrorMsg(); } else { echo “Opened database successfully\n”; } $sql =<<exec($sql); if(!$ret){ echo $db->lastErrorMsg(); } else { echo “Records created successfully\n”; } $db->close(); ?>
What’s wrong with the code? Do I need to copy any PHP library files into the folder of the project? If I can’t do this with PHP how do I connect with JavaScript?