0% found this document useful (0 votes)
6 views20 pages

PHP & MySQL Database Operations Guide

1. The document describes how to perform basic operations on a database with PHP and MySQL such as creating a database, connecting to it from a PHP page, performing searches with SELECT queries, and adding/updating/deleting data. 2. It recommends creating a separate "connection.php" page to hold the database connection code to simplify including it on multiple pages. 3. The search process involves creating a search form, submitting it to the same page via POST, using the submitted search term in a SELECT query to retrieve matching results from the database table into an array for output.

Uploaded by

Cha Yma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

PHP & MySQL Database Operations Guide

1. The document describes how to perform basic operations on a database with PHP and MySQL such as creating a database, connecting to it from a PHP page, performing searches with SELECT queries, and adding/updating/deleting data. 2. It recommends creating a separate "connection.php" page to hold the database connection code to simplify including it on multiple pages. 3. The search process involves creating a search form, submitting it to the same page via POST, using the submitted search term in a SELECT query to retrieve matching results from the database table into an array for output.

Uploaded by

Cha Yma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PHPwi

thMys
ql
CONTENT

1/
creat
eadat
abas
ewi
thphpmyadmi
n

2/
creat
etabl
esi
nsi
deadat
abas
e

3/
connec
tthewebs
itet
othec
reat
eddat
abas
ewi
thPHP

4/
per
for
m as
ear
chi
nthedat
abas
eus
ingSELECT

5/
adddat
atoat
abl
ewi
thADD

6/
del
etedat
afr
om t
abl
ewi
thDELETE

7/
updat
e(c
hange)exi
sti
ngdat
ainat
abl
ewi
thUPDATE

8/
perform morethenonequer r
yinasi
ngl
ereques
t(exa-
mple:twoSELECTqueriesatthesamet
imeorADDand
DELETEquerryatthesamet i
me)

10/
projec
t:si
tes
impletaaMERITti
l9aw hpr
esquel
faz
et
l
kolbidesi
gnetttaveckhal
ilr
eki
k

youwil
lprobabl
y ndmanys
pell
ingmi
stakes
5atermenic
hnthabi
tspel
li
ngwri9
CREATEADAT
ABASE
dat
abas
ename:«
tes

CREATEAT
ABLE
i
mportt
hetabl
esfr
om t
hetest
.sql l
ein
thefol
dert
othe«t
est»dat
abase
CONNECTTOTHE
CREATEDDATABASEWI
THPHP

c
onnec
[Link]
sehla I aamaliya aali5ir

I methode Ii ySdmou biha I plupart taa les prof mtaana iya inhom fi
page barka y3aytou Iii code taa I connexion 50 mara, lin I code yodSol
baadhou w yt3aba.
done I methode I plus efficace iya innik taamil page kahaw ismha
«[Link]», t7ot fiha I code taa I cnx mara kahaw.
◄ ► [Link]

<?php

$connection mysqli_connect('localhost', 'root', '');


( $connection){
("Database Connection Failed" mysqli_error($connection));

$select_db mysqli_select_db($connection, 'test');


( $select_db){
("Database Selection Failed" mysqli_er'r'Or'($connection));

I code eka dima yt3awid fi ay projet w bien sur kol wahid w kifch ykti
code taa connection, (ena niktbou ekika).
ma famech far9 bin mysql w mysqli fil Sidma, just zidou i baad kol mysql
(7keyit syntax) w fama 2 fonctions kahaw fil php mch nzidou fihom kil
variable $connection bch I code taana y5dim Ii ouma:
-mysqli_select_db($connection, 'test')
-mysqli_query($connection,$query)(mch nchoufouha I fonction edhi
chtaamil baad)
baad ma naamlou save Iii code edheka fi [Link], n3aytoulou fi
kol page niSdmouha w tist7a9 interraction maa database «test», w
niktbou fil head taa kol page I code php: <?php require('[Link]') ?>

◄ ► [Link]

<! html>
I < >
< >
< >index</

<?php ('[Link]'); ?>


</ >
.'
PERFORM ASEARCHI NTHEDAT
ABASE
WITHSELECT

s
ear
ch.
php
ki
fki
fma hac
hay
.

lawf
aradhnan7i
boun5arj
ounameli
sttaagr
oupe1wnaaml oul
ha
affichage tabl
eauht
ml parex,
onpassparl
esét
apesedhouma:

1/i
f(
iss
et($_POST[
's
ear
ch'
]))maaneha«kininzl
ouaalabout
onismaha
name=’search’
,ni
bdewsequenceofeventsil
i wis
t{}taal
if.

2/
n7ot
ouc
hoi
xmt
aana var
ibl
eis
mha$f
namel
ikes
o:

$_POST[’
name’]maanehan3aytouli
linputli
ismouname=’f
name’
lformulai
remtaanabilmethodpost,l c
asmt aanaouwat
ag
selec
tw wi st
’haoptionèt
.

kolopti
onaandhanamemt a7a,ki
tikl
ikic
hoixmtaak
lcodeyaar
afwahdoulii
nti
5tartparexrawiya,
mat i
st7a9i
ch
to93adkolmarat
ikt
ibki
mahaka:

edhikahi
yalf
azakini
staaml
ous
elec
twoptions
,si
nonken
nis
taamloui
nputaadi
nwa9t’
hatobl
igébc
hkolwahdat3ayt
il
ha
wahadha.
2/baadman7ot ouchoixmtaana vari
ble(samihkimat 7i
boui nti
),
tawikamc hnchoufoulvari
ableekachmichnaamloubi h,manec hmch
n5aliwi
hml awa7femika.ahnachnouwan7ibou?n7iboumi namel i
5tarnehntala3l
astnamemt e3ouwGPAz edami tableaumt e3ou
(groupe4).
doncylzimnan7adour equestmtaanawn7ot ouh variable
i
s mhaquer y:

chniyalfoncti
onmysqli
_quer y($c
onnecti
on,$query)?
lfoncti
onedhikayasidii
yal 5adam mtaakwalasana3mt aakwalac al
l
itkimat7ib,l
imchye5oul variabl
e$queryli halor dremt aakw
y7alil
hawbaadymc hi l
ildatabaseli
int
idejaconnec té ha( hi
nt:
kil
fazataarequir
econnecti
[Link])wt aamil
ikexécutioonlilordremtaak
vari
ableis
mha$result.

3/
whatisl
efttawikaiyal variablemt aana( $r
esul
t)chmichnaamlou
bi
ha?ti
ji
mt aamilbihailit7ib(lvari
ble),kimaaamaltenaparex,echo
si
mple,
emac houfoul synt axkifch,lmét hodetaalaffchageti
ji
mt aa-
mil
hakimat7ibinti(tabl eauht ml parex)

c
hniyalmysql
i_fetc
h_ar ray(
$resul
t)?lfonct
ionedhikayas i
dite5ouki
r
ésult
atmtaakwt aami ldouraaaltablecol
umnmt aakli hom l_name
wf_namewGPAwt aati
kGPAwal af_namewal al_namelimawj oud
t
ableau7as
bc hoixmt aaklimchyt saj
al lexecut
edor der$res
ul t
.

nor
malement ,
edhayaouwasearch,maf ama7at achayne9i
s,j
ust
e
qqetes
ttil
9awhom l pages
[Link](disponsableaadi
)w7aje
bar
katit
badeliyaki
fchmcht5ari
jrésult
atmt aak(t
ableauwalal
is
te
walaki
mal exekaaadiwbarchafazeto5ra.
..
.)
l
awf aradhnaliahnan7i boukin7il
lis
temt e3lesopti
onsmt e3i
lgoogle,ytl
3oulioumal esmm kilit ableaumte3imeghi r
mano93adni kt
ibbi l
opt i
onbi
l opt
ionwkol manaami l
ajoutl
studentwalaupdat e,automat
iquementl optionti
tbadel?s
ehla
laamaliya.

1/n7i
lout agtaas el
ectwbaadnj i
wbaadl opt
ionloula(li
ahna
7ati
nhat itl
aapardéf aut7adman7il
oul page googl ewbi en
suroptional),n7i
l c
odephps impl
e,c
odenaf s
ouyt 3awid,sel
ect
ettt,
justc houfoukini lfaz
awkahaw.(opens ear
ch_2.phpf or
thefull
c ode).
ADDDATATOATABLE
WITHADD

add.
php
n3awidmarao5ra,ma hac hay.
lcodel
i5di
mneh lins
ertmch
yt3awi
douwanaf sou,7aj
ewahidamchti
tbadel
iyal
ordremt
aana
($quer
y)wformulair
eo5rabiensur
.(mr
akazkenmaalphpwsql
rahousooo.
..

1/

2/or
drewi
limc
hyex
écut
ilor
dremt
e3i

7ajebar
kaylzi
mkom taar
fouha,
ouwal or
drebaadlval
ues
,yl
ziml
ordre reques
tmtaakykounnafsoul
it abl
eau:f
_namebaadl_name
baadGPA

3/li
5irnaaml
outes
tsi
mple(
opti
onal)bchnchouf
ousques
tudent
tz
edwalafamaer
reurwal
a7aj
e,t
aarafchaal
bla.
DELETEDAT
AFROMT ABLE
WITHDELETE

del
ete.
php
ki
laadama hchay,c
odeouwanaf
soumchyt3awi
d,wl7aj
elwahi
da
l
imchtit
badel
iyar
equest
,mchywal
idel
eteaadamar
aedhi
ya.

1/

2/

3/
tests
impl
ekilaada(
opt
ional
butr
ecommendedi
ncas
efamaghal
ta
lquer
ymtaa)
UPDATEDAT
AFROMT ABLE
WITH
UPDATE

updat
[Link]
ki
laadas
amec
ode,
reques
tkahawyt
badel
:

1/

2/

3/

4/
HOW TOPERFORM MORETHEN
ONEQUERYATETHESAME
TI
ME SYNT
AX+HOW TOUSE
MORETHENONET ABLE
ATTHESAMETIME

t
wo_quer
ies
.php
hnaki fkifmchn3awdounaf slcode,j
usten7ibnwarikom kifch
naaml oubar c
haquer i
esaumm t emps r eques
twahdaki ma2s elect
fardwa9twal a2del et
efardwahdawal aupdatewdel ete.
..7asi
lou,
j
us ten7ibnwar i
kom syntaxwkifchni
staamloulfonctionUNI ONt aa
sql,5atri
us ef
ull
aali5i
rwa9tel
itod5olbaadhikkiybdaf amabar chata-
bleauèt,doncistaamilUNIONwinbimoul èkwdimaymc hi.

parexempletj
ik ques
tiont9ol
ik5ar
ajl
ili
stetaast
udents(ki
ma l
exemplesear
chli
5dimneh)emal maraedhiyataa2tabl
eaux:gr
oupe4
wgroupe1.

1/

2/
out
put
:

===>c
hec
kther
estoft
hec
odei
ntwo_quer
ies
.php

You might also like