Sqlite php for beginners

Very important : tutorial for php sqlite. Not sql, not mysql, etc
you can't have a tutorial for sqlite without sql. that's like an eggless omelette: it doesn't exist!
94 Replies
ἔρως
ἔρωςOP16mo ago
the EXACT SAME base syntax works for sqlite and mysql sql is just the "base" language where all others derive from you can write most queries for mysql and sqlite, with 0 modifications
glutonium
glutonium16mo ago
i think she was talking about OP xD
No description
glutonium
glutonium16mo ago
what is "php sqlite" ? what's the diff between "php sqlite" and "sqlite"
lanszelot
lanszelot16mo ago
Sqlite you are using dbbrowser, or terminal Php sqlite you using website. You manage sql with php
lanszelot
lanszelot16mo ago
Gist
SQLite3 PHP Quickstart Tutorial
SQLite3 PHP Quickstart Tutorial. GitHub Gist: instantly share code, notes, and snippets.
glutonium
glutonium16mo ago
php sqlite is just an extension provided by php to interact with the sqlite DB? so what's the diff between the usage? what I'm understanding it's the same thing sqlite and php sqlite php sqlite is just the extension name which uses the same sqlite
lanszelot
lanszelot16mo ago
Please open the link. Is that same? Which sqlite have variables? $database Did you see any sql with variables?
glutonium
glutonium16mo ago
well I don't use sql or php that's why m asking lmao i mean i did practice sql, but a year ago don't quite Exactly remember everything
lanszelot
lanszelot16mo ago
I understand, but you confusing everyone. And no one will answer
glutonium
glutonium16mo ago
u r looking for video tutorials
lanszelot
lanszelot16mo ago
Any. Text, video, anything is good Video tutorials shows create database and that's it
glutonium
glutonium16mo ago
if u just search php sqlite u get all that
glutonium
glutonium16mo ago
No description
No description
glutonium
glutonium16mo ago
the manual isn't enough?
lanszelot
lanszelot16mo ago
Those are not . That is nothing. Create database and insert. And gone How to update? How to delete? How to count?
glutonium
glutonium16mo ago
aaah discord
lanszelot
lanszelot16mo ago
I did search . 1 week ago I am lookig and looking
glutonium
glutonium16mo ago
No description
glutonium
glutonium16mo ago
i mean just search up whenever u need something if u don't find 1 compact guide then just Search individual operations
lanszelot
lanszelot16mo ago
Problem is you not try those. Just drop me images. Those are not working I have to use variables. Not text. If you create php file and copy , you realise error here error there Not working
glutonium
glutonium16mo ago
what issue r u facing rn with your project? i believe u know how to connect but i assume your issue is you don't know how to do CRUD operation??
lanszelot
lanszelot16mo ago
Simple insert with variables. How to? With apostrophes or without? Create read update delete Crud Yes I know I know sql I don't know sql in php Why are you testing me? Why I would like to lie?
glutonium
glutonium16mo ago
calm down I'm not testing you I'm trying to understand the exact problem u have rn i am not talking about sql I'm asking if u know how to do these with php sqlite cause if u know how to do CRUD with php sqlite, what issue do u have then? not knowing how to use variables?
glutonium
glutonium16mo ago
Stack Overflow
how to use php variables make query for sqlite3
<?php /** * Simple example of extending the SQLite3 class and changing the __construct * parameters, then using the open method to initialize the DB. */ class MyDB extends SQLite3 { funct...
glutonium
glutonium16mo ago
u r asking for a tutorial but u said it yourself, u have been looking for tutorials but none suffices you so if u can't find a compact solution for all your problems search individually
lanszelot
lanszelot16mo ago
could you help me please how can I paste here php code?
glutonium
glutonium16mo ago
aah just copy paste in codeblock ```php // your code ```
lanszelot
lanszelot16mo ago
<?php
$nev = "Dorothy";
//file create or open if exist
$receptekData = new SQLite3("receptekdb.sqlite", SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
//error handling
$receptekData->enableExceptions(true);
//create table if not exist
$receptekData->query('CREATE TABLE IF NOT EXISTS "receptek" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
nev VARCHAR(100) NOT NULL,
)');

$receptekData->exec('BEGIN');
$receptekData->query('INSERT INTO "receptek" (
nev
VALUES (
"$nev"
)');
$receptekData->exec('COMMIT');
$receptekData->close();
<?php
$nev = "Dorothy";
//file create or open if exist
$receptekData = new SQLite3("receptekdb.sqlite", SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
//error handling
$receptekData->enableExceptions(true);
//create table if not exist
$receptekData->query('CREATE TABLE IF NOT EXISTS "receptek" (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
nev VARCHAR(100) NOT NULL,
)');

$receptekData->exec('BEGIN');
$receptekData->query('INSERT INTO "receptek" (
nev
VALUES (
"$nev"
)');
$receptekData->exec('COMMIT');
$receptekData->close();
this is php sqlite create db , create table, insert data but try it
glutonium
glutonium16mo ago
m on mobile
lanszelot
lanszelot16mo ago
inside you cannot found Dorothy the insert data will be $nev
glutonium
glutonium16mo ago
what does "nev" mean
lanszelot
lanszelot16mo ago
if I take out apostrophy error message "nev" is not a variable $nev is variable
glutonium
glutonium16mo ago
ik but I'm asking the meaning
lanszelot
lanszelot16mo ago
$nev sore "DOrothy" look at the top of the code php use variables what I have to give to sql php code results store in variables if someone write her name in insert box, and I would like to store, and phone number, or count something, and after she press the button to save datas, all those datas are in variables
glutonium
glutonium16mo ago
sorry but may ik what the issue is with the code u explained what it does or is supposed to do what bug does this code have
lanszelot
lanszelot16mo ago
so I have to give those variables value to the sql database
glutonium
glutonium16mo ago
it doesn't create a column named dorothy?
lanszelot
lanszelot16mo ago
I wrote to you : that code save into the database $name, not Dorothy
glutonium
glutonium16mo ago
you might be doing some syntax error in the place where u r inserting data
Jochem
Jochem16mo ago
PHP does not do variable replacement inside single quoted strings
$name = "Jochem";
echo "$name\n";
echo '$name\n';
$name = "Jochem";
echo "$name\n";
echo '$name\n';
output
Jochem
$name
Jochem
$name
lanszelot
lanszelot16mo ago
that is php only not php sqlite not the same
glutonium
glutonium16mo ago
r u sure?
Jochem
Jochem16mo ago
it really is the same
lanszelot
lanszelot16mo ago
php does not do "CREATE TABLE" too
Jochem
Jochem16mo ago
$receptekData->query("INSERT INTO 'receptek' (
nev
VALUES (
'$nev'
)");
$receptekData->query("INSERT INTO 'receptek' (
nev
VALUES (
'$nev'
)");
try that
glutonium
glutonium16mo ago
that's the sqlite part variable replacement is php part but whatever, try what jochem said
lanszelot
lanszelot16mo ago
Your code
Jochem
Jochem16mo ago
not my code at all, you didn't replace the quotes just after the opening bracket you can't have single quotes in a single quoted string, just as you can't have double quotes in a double quoted string not without escaping them, at least
glutonium
glutonium16mo ago
what if u do "'$nav'"
Jochem
Jochem16mo ago
that's not going to work, it's still in the original string PHP strings are multiline
glutonium
glutonium16mo ago
hmm ok \ won't work here either?
Jochem
Jochem16mo ago
it will, but you can also just switch the quotes from double to single
glutonium
glutonium16mo ago
k
lanszelot
lanszelot16mo ago
I am on it, please give me a minute Fatal error: Uncaught Exception: near ")": syntax error in
Jochem
Jochem16mo ago
did you change the end quote?
lanszelot
lanszelot16mo ago
copy paste you said I wrote wrong, so I copy paste it
Jochem
Jochem16mo ago
did you change the CREATE TABLE part back too?
lanszelot
lanszelot16mo ago
no. how should I have to?
glutonium
glutonium16mo ago
i think u might wanna know more about the syntax as well since u r having issues with quotes
Jochem
Jochem16mo ago
yeah, I'd honestly recommend going through the base part of PHP's manual, it explains string syntax excellently
lanszelot
lanszelot16mo ago
this is why I am looking a tutorial
glutonium
glutonium16mo ago
I'm talking about php
Jochem
Jochem16mo ago
this isn't a "php sqlite" issue, this is a very basic PHP issue
glutonium
glutonium16mo ago
not php sqlite
Jochem
Jochem16mo ago
you've got an extra comma at the end of nev VARCHAR
lanszelot
lanszelot16mo ago
Fatal error: Uncaught Exception: near "VALUES": syntax error in I got extra, because I am doing fast, just write this quick error in 14
Jochem
Jochem16mo ago
you're missing a closing parenthesis after 'nev'
glutonium
glutonium16mo ago
damn man u really need to fix these bugs yourself
Jochem
Jochem16mo ago
I strongly recommend you take some time and learn the basics of the tools you're using
glutonium
glutonium16mo ago
☝️ r u doing some sort of assignment? or school or college project?
lanszelot
lanszelot16mo ago
no only hobby
glutonium
glutonium16mo ago
then why rush? take it slow and learn slowly
lanszelot
lanszelot16mo ago
1 week ago I try to do this. I am not rush. I need a tutorial. To learn
glutonium
glutonium16mo ago
u r in rush u r facing issue with basic php bugs u should practice that first
lanszelot
lanszelot16mo ago
I wrote quick
glutonium
glutonium16mo ago
and that's rush
lanszelot
lanszelot16mo ago
and I have dislexy I wrote this to you to not wait
glutonium
glutonium16mo ago
how long have u been practicing php?
Jochem
Jochem16mo ago
you need to take a step back and learn more of the basics. You were asking for a PHP sqlite tutorial, but the issue you've presented here was simply a misunderstanding of the very basics of the way PHP handles strings. You don't have the background information necessary to identify what tutorials you need to follow, so you need to take a step back to the basics of the tools you're using
lanszelot
lanszelot16mo ago
few years
glutonium
glutonium16mo ago
really?
lanszelot
lanszelot16mo ago
yes
glutonium
glutonium16mo ago
i doubt but ok
lanszelot
lanszelot16mo ago
I created a family tree site to my mom
glutonium
glutonium16mo ago
ok
lanszelot
lanszelot16mo ago
never mind I am still looking some sql php tutorial one week ago just waste time
glutonium
glutonium16mo ago
.
Jochem
Jochem16mo ago
@lanszelot please don't delete your questions when you're done with them. Others might still be able to learn from the answers people gave
ἔρως
ἔρωςOP16mo ago
i was thinking about this
lanszelot
lanszelot16mo ago
I try to delete all, because it was not solved
Jochem
Jochem16mo ago
Still might help someone, so please don't
lanszelot
lanszelot16mo ago
I think it only confuse anyone php sqlite tutorial not found anywhere
Jochem
Jochem16mo ago
You never know what helps someone else. It's gone to leave it up
lanszelot
lanszelot16mo ago
in this case sorry, I just try to do what I thought it is good and what I thought I have to do

Did you find this page helpful?