This is my first php program!


Advanced Database Techniques



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

Advanced Database Techniques
|
201
echo "\n";
}
echo "
$k";
if (is_array($v)) {
a_to_table($v);
} else {
print_r($v);
}
echo "
\n";
}
Figure 8-2 shows the output of the table information dumper.
Sequences
Not every RDBMS has the ability to assign unique row IDs, and those that do have
wildly differing ways of returning that information. PEAR DB sequences are an alter-
native to database-specific ID assignment (for instance, MySQL’s
AUTO_INCREMENT
).
The
nextID( )
method returns the next ID for the given sequence:
$id = $db->nextID(
sequence
);
Normally you’ll have one sequence per table for which you want unique IDs. This
example inserts values into the
movies
table, giving a unique identifier to each row:
$movies = array(array('Dr No', 1962),
array('Goldfinger', 1965),
array('Thunderball', 1965));
Figure 8-2. The information from tableInfo( )
,ch08.16110 Page 201 Wednesday, March 13, 2002 11:44 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.
202
|
Chapter 8: Databases
foreach ($movies as $movie) {
$id = $db->nextID('movies');
splice($movie, 0, 0, $id);
$db->query('INSERT INTO movies (id,title,year) VALUES (?,?,?)', $movie);
}
A sequence is really a table in the database that keeps track of the last-assigned ID.
You can explicitly create and destroy sequences with the
createSequence( )
and
dropSequence( )
methods:
$res = $db->createSequence(
sequence
);
$res = $db->dropSequence(
sequence
);
The result will be the result object from the create or drop query, or
DB_ERROR
if an
error occurred.
Metadata
The
getListOf( )
method lets you query the database for information on available
databases, users, views, and functions:
$data = $db->getListOf(
what
);
The
what
parameter is a string identifying the database feature to list. Most data-
bases support
"databases"
; some support
"users"
,
"views"
, and
"functions"
.
For example, this stores a list of available databases in
$dbs
:
$dbs = $db->getListOf("databases");
Transactions
Some RDBMSs support
transactions
, in which a series of database changes can be
committed (all applied at once) or rolled back (discarded, with the changes not applied
to the database). For example, when a bank handles a money transfer, the withdrawal
from one account and deposit into another must happen together—neither should
happen without the other, and there should be no time between the two actions.
PEAR DB offers the
commit ( )
and
rollback( )
methods to help with transactions:
$res = $db->commit( );
$res = $db->rollback( );
If you call
commit( )
or
rollback( )
on a database that doesn’t support transactions,
the methods return
DB_ERROR
.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   56   57   58   59   60   61   62   63   ...   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