PDO (php (as the mainstream development language) Data Object) is a new php (as the mainstream development language) 5, in php (as the mainstream development language) when php (as the current mainstream development language) 6 only uses PDO by default to process databases, and all database extensions are moved to PECL, by default, php is not our favorite (as the mainstream development language) _ MySQL (the best combination with PHP ). dll and so on, then how to handle it, we only have to keep pace with the times, I will try a little PDO. (This article is only an entry level. You can skip it)
[What is PDO]
PDO is a major new feature of php (as the mainstream development language) 5, because in php (as the mainstream development language) 5 previous php (as the current mainstream development language) 4/php (as the current mainstream development language) 3 are a bunch of database extensions to connect and process various databases, what is php (as the mainstream development language) _ MySQL (the best combination with PHP ). dll, php (as the mainstream development language) _ pgsql. dll and php (as the mainstream development language) _ mssql (a powerful database platform on WINDOWS ). dll, php (as the mainstream development language) _ sqlite. dll and other extensions to connect to MySQL (the best combination with PHP), PostgreSQL, MS SQL server (WINDOWS powerful database platform), SQLite, the same, we must use the database abstract classes such as ADOdb, PEAR: DB, and php (as the mainstream development language) lib: DB to help us It is extremely cumbersome and inefficient. After all, how can we directly use C/C ++ to write the code efficiency of php (as the current mainstream development language) with a high scaling slope? Therefore, the emergence of PDO is inevitable. you should accept it with a calm learning attitude. Maybe you will find it can reduce your efforts.
[Install PDO]
I am on Windows XP SP2, so the whole process is performed on Windows. For Linux/FreeBSD and other platforms, please find the information to set and install.
My php (as the mainstream development language) 5.1.4 already comes with php (as the mainstream development language) _ pdo. dll extension, but you need to set it a little bit before using it.
Open c: windowsphp (as the mainstream development language). ini, which is my php (as the mainstream development language) configuration file, find the following line:
Extension_dir
This is the directory for our extension. My php (as the current mainstream development language) 5 extension is in: C: php (as the current mainstream development language) 5ext, then I will change this line:
Extension_dir = "C:/php (as the mainstream development language) 5/ext"
Then, find php (as the current mainstream development language). ini:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions;
;;;;;;;;;;;;;;;;;;;;;;
Below are a bunch of similar; extension = php (as the mainstream development language) _ mbstring. dll, here is the php (as the mainstream development language) Extension load configuration, we add our PDO extension at the end:
Extension = php (as the mainstream development language) _ pdo. dll
Extension = php (as the mainstream development language) _ pdo_MySQL (the best combination with PHP). dll
Extension = php (as the mainstream development language) _ pdo_pgsql.dll
Extension = php (as the mainstream development language) _ pdo_sqlite.dll
Extension = php (as the mainstream development language) _ pdo_mssql (powerful database platform on WINDOWS). dll
Extension = php (as the mainstream development language) _ pdo_odbc.dll
Extension = php (as the mainstream development language) _ pdo_firebird.dll
; Extension = php (as the mainstream development language) _ pdo_oci8.dll
All kinds of PDO drivers can be added, but the following php (as the mainstream development language) _ pdo_oci8.dll does not exist because I have not installed the Oralce database, comment it out with a semicolon. Then restart our Web server, iis (Microsoft's WEB server platform)/apache (the most popular WEB server platform for Unix), and iis (Microsoft's WEB server platform ), hey, the table despise me. It's easy on Windows.
After the restart, write a php file (as the current mainstream development language) info. php (as the current mainstream development language) under the document directory of our Web server, and add the following:
<?
Php (as the mainstream development language) info ();
?>
Then open our lovely Browser: IE/FireFox. I use FireFox 2.0. I just downloaded it. It's so nice. I'm not afraid of rogue software. Haha.
Enter http: // localhost/php in the browser (as the mainstream development language) info. php (as the mainstream development language), if the path of your page is inconsistent, enter it by yourself.
In the output content, if you can see smoothly:
PDO
PDO support enabled
PDO drivers MySQL (the best combination with PHP), pgsql, sqlite, and mssql (a powerful database platform on WINDOWS), odbc, and firebird
Various drivers will be explained later: PDO_Firebird, pdo_mssql (a powerful database platform on WINDOWS), pdo_MySQL (the best combination with PHP), PDO_ODBC, pdo_pgsql, pdo_sqlite
Congratulations, you have successfully installed it. Otherwise, Please carefully check the above steps.
[Try a knife]
I use MySQL (the best combination with PHP) 4.0.26, but I personally recommend that you use MySQL (the best combination with PHP) 4.1.x or MySQL (the best combination with PHP) 5.0.x, because there are many interesting things worth learning. Here we need to connect PDO to MySQL (the best combination with PHP) 4.0. If you have not installed MySQL (the best combination with PHP), install it on your own. We have established MySQL (the best combination with PHP), and added table foo in the test Library, including four fields: id, name, gender, and time.
We started to construct the first PDO application and create a pdo. php (as the mainstream development language) file under the Web document directory:
<? Php (as the mainstream development language)
$ Dsn = "MySQL (the best combination with PHP): host = localhost; dbname = test ";
$ Db = new PDO ($ dsn, root ,);
$ Count = $ db-> exec ("insert into foo SET name = heiyeluren, gender = male, time = NOW ()");
Echo $ count;
$ Db = null;
?>