This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet54/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   50   51   52   53   54   55   56   57   ...   69
Bog'liq
PHP

Option
Controls
persistent
Connection persists between accesses
optimize
What to optimize for
debug
Display debugging information
,ch08.16110 Page 194 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.
PEAR DB Basics
|
195
$db = DB::connect($datasource);
if (DB::isError($db)) {
die($db->getMessage( ));
}
The
DB::isError( )
method returns
true
if an error occurred while working with the
database object. If there was an error, the usual behavior is to stop the program and
display the error message reported by the
getMessage( )
method. You can call
getMessage( )
on any PEAR DB object.
Issuing a Query
The
query( )
method on a database object sends SQL to the database:
$result = $db->query(
sql
);
A SQL statement that doesn’t query the database (e.g.,
INSERT
,
UPDATE
,
DELETE
)
returns the
DB_OK
constant to indicate success. SQL that performs a query (e.g.,
SELECT
) returns an object that you can use to access the results.
You can check for success with
DB::isError( )
:
$q = $db->query($sql);
if (DB::iserror($q)) {
die($q->getMessage( ));
}
Fetching Results from a Query
PEAR DB provides two methods for fetching data from a query result object. One
returns an array corresponding to the next row, and the other stores the row array
into a variable passed as a parameter.
Returning the row
The
fetchRow( )
method on a query result returns an array of the next row of results:
$row = $result->fetchRow([
mode
]);
This returns either an array of data,
NULL
if there is no more data, or
DB_ERROR
if an
error occurred. The
mode
parameter controls the format of the array returned, which
is discussed later.
This common idiom uses the
fetchRow( )
method to process a result, one row at a
time, as follows:
while ($row = $result->fetchRow( )) {
if (DB::isError($row)) {
die($row->getMessage( ));
}
// do something with the row
}
,ch08.16110 Page 195 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.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   50   51   52   53   54   55   56   57   ...   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