This is my first php program!


Advanced Database Techniques



Download 6,9 Mb.
Pdf ko'rish
bet58/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   54   55   56   57   58   59   60   61   ...   69
Bog'liq
PHP

Advanced Database Techniques
|
199
The
executeMultiple( )
method takes a two-dimensional array of values to insert:
$responses = $db->executeMultiple(
compiled
,
values
);
The
values
array must be numerically indexed from 0 and have values that are arrays
of values to insert. The compiled query is executed once for every entry in
values
,
and the query responses are collected in
$responses
.
A better way to write the movie-insertions code is:
$movies = array(array('Dr No', 1962),
array('Goldfinger', 1965),
array('Thunderball', 1965));
$compiled = $q->prepare('INSERT INTO movies (title,year) VALUES (?,?)');
$db->insertMultiple($compiled, $movies);
Shortcuts
PEAR DB provides a number of methods that perform a query and fetch the results
in one step:
getOne( )
,
getRow( )
,
getCol( )
,
getAssoc( )
, and
getAll( )
. All of these
methods permit placeholders.
The
getOne( )
method fetches the first column of the first row of data returned by an
SQL query:
$value = $db->getOne(
SQL
[,
values
]);
For example:
$when = $db->getOne("SELECT avg(year) FROM movies");
if (DB::isError($when)) {
die($when->getMessage( ));
}
echo "The average James Bond movie was made in $when";
The average James Bond movie was made in 1977
The
getRow( )
method returns the first row of data returned by an SQL query:
$row = $db->getRow(
SQL
[,
values
]]);
This is useful if you know only one row will be returned. For example:
list($title, $actor) = $db->getRow(
"SELECT movies.title,actors.name FROM movies,actors
WHERE movies.year=1977 AND movies.actor=actors.id");
echo "($title, starring $actor)";

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   54   55   56   57   58   59   60   61   ...   69




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish