In the website background, you often have to deal with databases. This article describes how to use XAMPP to manage MySql Databases and How to Use PHP to access MySql databases. 1. Use XAMPP to manage MySql databases first use XAMPP to open the MySql Management page. Follow these steps: Start XAMPP and click Admin to go to The XAMPPforWindows homepage.
In the website background, you often have to deal with databases. This article describes how to use XAMPP to manage MySql Databases and How to Use PHP to access MySql databases. 1. Use XAMPP to manage MySql databases first use XAMPP to open the MySql Management page. Follow these steps: Start XAMPP and click Admin to go to the home page of XAMPP for Windows.
In the website background, you often have to deal with databases. This article describes how to use XAMPP to manage MySql Databases and How to Use PHP to access MySql databases.
1. Use XAMPP to manage MySql Databases
Use XAMPP to open the MySql Management page. Follow these steps: Start XAMPP and click Admin to go to the home page of XAMPP for Windows. Click phpMyAdmin on the home page.
On the phpMyAdmin page, create a database test and create a t_student table in the database. The table contains three fields: id, name, and age.
Then you can start to use PHP to access the MySql database. Since PHP has encapsulated the MySql database, it is very easy to access MySql with PHP.
Ii. PHP accessing MySql database
The following PHP program accesses the t_student table in the test database, reads data, and outputs data in the form of tables. The Code is as follows:
// By MoreWindows (http://blog.csdn.net/MoreWindows) // defines the constant define (DB_HOST, 'localhost'); define (DB_USER, 'root'); define (DB_PASS, '123 '); define (DB_DATABASENAME, 'test'); define (DB_TABLENAME, 't_ student '); // name of the database table column $ dbcolarray = array ('id', 'name ', 'age'); // mysql_connect $ conn = mysql_connect (DB_HOST, DB_USER, DB_PASS) or die ("connect failed ". mysql_error (); mysql_select_db (DB_DATABASENAME, $ conn); // read the number of records in the table $ SQL = sprintf ("select count (*) from % s", DB_TABLENAME ); $ result = mysql_query ($ SQL, $ conn); if ($ result) {$ count = mysql_fetch_row ($ result);} else {die ("query failed ");} the echo table contains $ count [0] records.
"; $ SQL = sprintf (" select % s from % s ", implode (", ", $ dbcolarray), DB_TABLENAME); $ result = mysql_query ($ SQL, $ conn); // table echo'
'; // Header $ thstr ="
". Implode (" |
", $ Dbcolarray )." | "; Echo $ thstr; // while ($ row = mysql_fetch_array ($ result, MYSQL_ASSOC) in the table content // equivalent to $ row = mysql_fetch_assoc ($ result) {echo"
"; $ Tdstr =" "; foreach ($ dbcolarray as $ td) $ tdstr. ="
$ Row [$ td] | "; Echo $ tdstr; echo"
";} Echo"
"; Mysql_free_result ($ result); mysql_close ($ conn );
The running result is as follows:
This HTML element is completely output by PHP. This section describes how to use smarty to read the database and 《Add, delete, modify, and set the color of the odd and even rows in the jquery table.To set the color of the table's parity rows.
Http://blog.csdn.net/morewindows/article/details/7086524