PHP NOTE PART-3 (Working With Databases-1)
PHP NOTE PART-3 (Working With Databases-1)
antaoductfbn do HYsqL
unyoimatfon
MYSQL an epen souiCe Stuchired
&uey Language (sq-) database ha ast, varlabe
se and sultable to appiRcotton e
any stze ,
Databae
myso
test
poseb.
xDatabase tablas ana stoTad inside databas6,
Cveate database . ou
So the fist step so a
MYsQL monitan
F SHON DA TABRSES
Database
maysa
test
Pacdute
Database ehanged
Case nsensttive.
6ersitfve.
tables
o s o w S eaeh
a colectfon
*A able
ecoad each a e c o r d
holding data fo ne
NCws
alled falds.
Contairing foamatfon
CREATING a New Table:
hLumben VARCHAR(20)
Tables-h- pacduce
fallowing Command,
name nuumbe
aPples o90
0anges 3329
bananas 8582
a mys4L sven.
8 ntac
mYsQL
ben name the Usenname
can cal
functon ou
a umben o
they ae stedl
and
Sntenac uith MYSQ
belouo table.
nthee
FUNCTIONS MEANINGS
MYSQL senven.
database
n a aesult
table the
mua-teld- table 4et the name o the
% n.
e n eld
a aesult,
Seye.
mupo- Ist-ffelds |kst MvsQL table ffelds
a MYSQL detabas«
Muysal s t -tables tst the tables
telds n nesut.|
mya-num-ftelds Get the numben o
MYSQL savG.
42 php
Connectfon mysqlconnet ("Mocalhost voot, ***
97
o the Database:
Connectfng
yntan:
Example
Php
*m** *
GConnectioh msalL Connect (C "localhost", "ioot ",
Oa dee Ccouldh't Conneck *o seven )33
411
Readtngthe Table and Displaytng
and dlsplay the
do o1ead
The gcal
can send xhat
shat
named ut. You
database table
the allowtng functfon
uncton,
ustng
SNea an sQL ueny
Syntan
uuny ( u L E ,
Ttnk - identf4ten )
mys
Example paogram
<hemdz
head 4Rtte7 Dbplayng tables with MveaL 21tHez
lhead
Abody
hi> Dtsplayfng tables with MYsQL4th1z
phP
connetfen iysql-connect C"'localhost", "root ", ***")
co dfe C"cannot Connect to the senyn )3
Sa SELECT*FROM fuult
$esult
mysal-quexy ($quvy) on dle ('quy falled:.|
meso evon)5
echo table bondan = 'i 'z "3
echo
ech tn">
echo td>", 41ow [ name'], 'ztd7<tdY , trouo[ numbei
cltcd"
ech len7"3
echo ttane7"3
msaelose C¢connectton )
lbody <lhtml7
Output
dRsplay tables. php
D%playing dables ulth MY44L
Name Numbe
apples
0rans 332
bananas 8582
UPdatina Databases:
42Php
Beonnedtfon =Msal.connectC"loealhost ",noot", "*** **
ea dae C"annot comect do the seave")s
db mysal- select-db ("paodugtce)connectfon)
on dte C"Cannot select he, database")
NHERE
$u upDATE fult SET numben
==lovoo
hame bananas
aa dte ( 'Quyfailed:
$aesult =
mysal_quuy C$quuy)
mysgl-ek10 C)3
echo t7
echo td>", znouo['name'J, Zltd7ktd>, $row['numbia'],
ltd'
echo ttnz's
echo table
mysot elose ($tonnectfon)
7
Output
vpdatetable iphp
Name Numben
apples.
Caanges 3329
looo
bananas
Tnsentng ito tahes new data:
Example
4Php
onectfon = mysal-Connect ( "Jocalhest" noot", ****")
on die C "Couldnt Conneck, o the seven");s
db mysgk- select-db "Paduce "; ¢eonnecfon)
0 dfe "Gouldn't selec the database")3
VALUES
4iyz INSERT INTO fult name, numben)
"
nesult -
mysal-9uny C$uuny)
0n dte C"Quy falled mysal-evoa419
echo table bonden''z'3
echo "t7"
Numben <l&h7
echo Ztn7 Name hh7 <th7
echottx7"
3
echo Ztable7
mMusalelose ( $connectfen)
97
utput:
@inswtdatafntotable-ph
Name Nurbenr
apples L020
Mangos
Delefng Reconds
Example
4Php
"*****
fconnectfon = mjsconneet ("ocalhest", 2opt",
Cn dle (Camot onnect to the&nYELSE ") 3
Seven
Jdb mgal.select-dbProduce, $eonnectfon
091 die'annot slect he database ") 3
echo AA7"
'kHd>{td7, $row['nuumben'J,
echo td>, rowl 'name'],
echo ta7's
echo Ktable";
mysok close (3tonnectfon)s
7
Output:
@deletedatafromtable. php
Name Numbea
Onangs 3329
bananas lobb
3ooo
Mangos