This is my first php program!



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

PEAR DB Basics
|
193
the database, and more. The components of a DSN are assembled into a URL-like
string:
type(dbsyntax)
://
username
:
password
@
protocol
+
hostspec
/
database
The only mandatory field is
type
, which specifies the PHP database backend to use.
Table 8-1 lists the implemented database types at the time of writing.
Figure 8-1. The movie page
Table 8-1. PHP database types
Name
Database
Mysql
MySQL
Pgsql
PostgreSQL
Ibase
InterBase
Msql
Mini SQL
Mssql
Microsoft SQL Server
oci8
Oracle 7/8/8
i
Odbc
ODBC
Sybase
SyBase
Ifx
Informix
Fbsql
FrontBase
,ch08.16110 Page 193 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.
194
|
Chapter 8: Databases
The
protocol
is the communication protocol to use. The two common values are
"tcp"
and
"unix"
, corresponding to Internet and Unix domain sockets. Not every
database backend supports every communications protocol.
These are some sample valid data source names:
mysql:///webdb
mysql://localhost/webdb
mysql://bondview@localhost/webdb
mysql://bondview@tcp+localhost/webdb
mysql://bondview:007@localhost/webdb
In Example 8-1, we connected to the MySQL database
webdb
with the username
bondview
and password
007
.
A common development technique is to store the DSN in a PHP file and include that
file in every page that requires database connectivity. Doing this means that if the
information changes, you don’t have to change every page. In a more sophisticated
settings file, you might even switch DSNs based on whether the application is run-
ning in development or deployment mode.
Connecting
Once you have a DSN, create a connection to the database using the
connect( )
method. This returns a database object you’ll use for tasks such as issuing queries
and quoting parameters:
$db = DB::connect(
DSN
[,
options
]);
The
options
value can either be Boolean, indicating whether or not the connection is to
be persistent, or an array of options settings. The
options
values are given in Table 8-2.
By default, the connection is not persistent and no debugging information is dis-
played. Permitted values for
optimize
are
'performance'
and
'portability'
. The
default is
'performance'
. Here’s how to enable debugging and optimize for portability:
$db = DB::connect($dsn, array('debug' => 1, 'optimize' => 'portability'));
Error Checking
PEAR DB methods return
DB_ERROR
if an error occurs. You can check for this with
DB::isError( )
:
Table 8-2. Connection options

Download 6,9 Mb.

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