Some PHP tutorials

Source: Internet
Author: User
Some PHP knowledge. 1. how to configure PhpMyAdmin2.9 the configuration files of many tutorials on the network are for the PhpMyAdmin base version. I didn't know where to put the 2.9 configuration file at first? The relative address of the configuration file is: 1. how to configure PhpMyAdmin2.9
The configuration files of many tutorials on the network are for the PhpMyAdmin base version. at first, I didn't even know where to put the 2.9 configuration file?
The relative address of the configuration file is: Config. sample. inc. php(Not this libraries/config. default. inc. php)

2. ask phpMyAdmin to log on with a password
Set the following parameters in config. inc. php:
$ Cfg ['servers'] [$ I] ['auth _ type'] = 'cooker ';
$ Cfg ['blowfish _ secret'] = '000000'; // you can specify a non-empty string.
$ Cfg ['defaultlang '] = 'zh'; // Chinese characters are displayed by default. optional.

3. no extension settings for PHP are found. However, the wide character set seems to be used in the current system. The extension = php_mbsting.dll file of php. ini does not have to be modified!

4. When php reads Chinese characters from the mysql database, are all question marks displayed?
Before querying a database, use mysql_query ("set names 'gb2312 '");

5. use PHP to output static pages

There are 2 types

One is to use the template technology, and the other is to use ob series functions. Both methods look similar, but they are actually different.

First: use templates

At present, PHP templates can be said to be many, including powerful smarty and easy-to-use smarttemplate.

Each of these templates has a function to get the output content.

We use this function to generate static pages.

The advantage of using this method is that the code is clear and readable.

Here I use smarty as an example to illustrate how to generate static pages.

Require ('smarty/smarty. class. php ');
$ T = new Smarty;
$ T-> assign ("title", "Hello World! ");
$ Content = $ t-> fetch ("templates/index.htm ");
// Here fetch () is the function used to obtain the Output content. in the $ content variable, it is the content to be displayed.
$ Fp = fopen ("archives/2005/05/19/0001 .html", "w ");
Fwrite ($ fp, $ content );
Fclose ($ fp );
?>

Method 2: Use ob functions

The functions used here are mainly ob_start (), ob_end_flush (), ob_get_content (),

Here, ob_start () indicates opening the browser buffer,

After the buffer is enabled, all non-file header information from the PHP program will not be sent,

Instead, it is saved in the internal buffer until you use ob_end_flush ().

The most important function here is ob_get_contents (),

This function is used to obtain the buffer content, which is equivalent to the above fetch (),

The same is true. Code:

Ob_start ();
Echo "Hello World! ";
$ Content = ob_get_contents (); // retrieves all the content output on the php page.
$ Fp = fopen ("0001.html", "w ");
Fwrite ($ fp, $ content );
Fclose ($ fp );
?>
6. PHP database reading details
The functions of this code are as follows:

Connect to a mysql server whose url is localhost and Port is 3306. The account and password of the mysql server are "root" and "9999 ". The mysql server has a database "OK" and a table "abc" in the database. The abc table has two columns: "id" and "name". The column names read all the data in abc.


$ Dbh = @ mysql_connect ("localhost: 3306", "root", "9999 ");

/* Define the variable dbh. the mysql_connect () function means to connect to the mysql database, and "@" means to block the error */

If (! $ Dbh) {die ("error ");}

/* The die () function means to send the strings in brackets to the browser and interrupt the PHP program (Script ). The parameters in the brackets are the strings to be sent. */

@ Mysql_select_db ("OK", $ dbh );

/* Select a database on the mysql server. the database name is OK */

$ Q = "Select * FROM abc ";

/* Define the variable q. "Select * FROM abc" is an SQL statement that reads data in table abc */

?>








$ Rs = mysql_query ($ q, $ dbh );

/* Define the rs variable. the Function mysql_query () indicates that the query string is sent for MySQL to perform related processing or execution. since php is executed from right to left, the rs value is the value returned after the server runs the mysql_query () function */

If (! $ Rs) {die ("Valid result! ");}

Echo"









";Echo" ";While ($ row = mysql_fetch_row ($ rs) echo" ";/* Define the volume change (array) row and write the data one by one using the while loop.The mysql_fetch_row () function means to split the query result $ rs into an array variable.$ Row [0] and $ row [1] can be changed */Echo"
ID Name
$ Row [0] $ Row [1]
";

?>








$ Rs = mysql_query ($ q, $ dbh );

While ($ row = mysql_fetch_object ($ rs) echo "$ row-> id $ row-> name
";

/* The id and name can be changed */

?>








$ Rs = mysql_query ($ q, $ dbh );

While ($ row = mysql_fetch_array ($ rs) echo "$ row [id] $ row [name]
";

/* The id and name can be changed */

?>




@ Mysql_close ($ dbh );

/* Close the connection to the mysql database */

?>

The configuration files of many tutorials on the idea network are for the PhpMyAdmin base version. at first, I didn't even know where to put the 2.9 configuration file? The relative address of the configuration file is :...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.