Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the role of PHP PEAR DB class in website construction?

Shulou Source: shulou.com Published: 2022-06-03 04:23:00 09月22日 Update

This article introduces how the role of PHP PEAR DB in website construction is reflected, and the content is very detailed. Interested friends can use it for reference and hope to be helpful to you.

PHP language is widely used, of course, the most frequently used place is in the development and construction of the website. Today we will introduce you about the role of PHP PEAR DB classes in website development.

In the development of PHP website, because it supports a variety of database engines, such as Mysql,Mssql,Pgsql,sqlite, and provides different functions as interfaces for various database systems, it brings a lot of convenience to PHP website developers.

But at the same time, it also brings the problem of platform portability, with the change of the underlying database, the PHP code must also be changed. There are various solutions to this problem, such as using PHP ADODB classes, PHP PEAR DB classes or writing PHP DB classes by yourself, aggregating the functional operations of various databases, and so on. Today, I will share with you how to install and use PHP PEAR DB classes to achieve access to different databases.

Preparatory work

1. Before using the PHP PEAR DB class to access the database, you need to install PHP PEAR, and then download and install the DB class, namely pear install db, through PEAR.

2. Install relevant databases, such as Mysql,Mssql,Pgsql,Sqlite, as needed, find Dynamic Extensions in PHP.INI, introduce the DLL file of the corresponding data, and restart Apache.

Note: since I am using DedeAMPZ, I must install PHP PEAR in the DedeAMPZ\ WebRoot\ Default directory when I install it, otherwise I will report a Failedopening required 'DB.php' error when introducing DB.php, that is, I cannot find the DB class (could not find pear db library), because DedeAMPZ may have restrictions on the relevant directories.

Example of using PHP PEAR DB class

< ? require_once("DB.php"); $userName = 'root'; $password = '123456'; $hostName = 'localhost'; $dbName = 'test'; $dsn = "mysql://$userName: $password@$hostName/$dbName"; $dbCon = DB::connect($dsn); if (DB::isError($dbCon)) { die ($dbCon->

GetMessage ()

}

$sql = "CREATE TABLE leapsoul (".

`id` INT (11) UNSIGNED NOT NULL, ".

"`name` VARCHAR (30) CHARACTER

SET gbk COLLATE gbk_chinese_ci NOT NULL, ".

"`age` INT (2) NOT NULL,".

"`dayday` VARCHAR (30) CHARACTER

SET gbk COLLATE gbk_chinese_ci NOT NULL, ".

"`sex` INT (1) NOT NULL,"

"PRIMARY KEY (`id`)".

") ENGINE = MYISAM CHARACTER SET gbk

COLLATE gbk_chinese_ci "

$result = $dbCon- > query ($sql)

If (DB::isError ($result)) {

Die ($result- > getMessage ())

}

$sql = "insert into leapsoul (id,name)

Age,birthday,sex) values (1) LeapSoul

'2009-05-13), (2), (2)

(3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3), (3).

$result = $dbCon- > query ($sql)

If (DB::isError ($result)) {

Die ($result- > getMessage ())

}

$dbCon- > setFetchMode (DB_FETCHMODE_ASSOC)

$sql = "select * from leapsoul"

$result = $dbCon- > query ($sql)

If (DB::isError ($result)) {

Die ($result- > getMessage ())

}

For ($ionometrich _ inumRows (); $iTunes +)

{

$info = & $result- > fetchRow ()

Echo "name:". $info ['name']

Echo "birthday:". $info ['birthday']. "

"

}

$result- > free ()

$dbCon- > disconnect ()

}

On the role of PHP PEAR DB class in website construction is how to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Data database website development function construction website construction different content function at the same time more directory website development problem help good code interest function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology Xiaomi macOS Docker