Entry: PHP and MYSQL integration _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Getting started: combining PHP with MYSQL ., Connect to the database? Php $ dbhostlocalhost; $ dbuserroot; your mysql username $ dbpass123456; your mysql password $ dbnamedata; your mysql database name connects to the local database , Connect to the database

$ Dbhost = localhost;
$ Dbuser = root; // your mysql User name
$ Dbpass = 123456; // your mysql password
$ Dbname = data; // your mysql database name

// Connect to the local database
$ GLOBALS ["conn"] = mysql_connect ($ dbhost, $ dbuser, $ dbpass );

// Open the database
Mysql_select_db ($ dbname, $ GLOBALS ["conn"]);

?>

2. read a field value from the database.

// Read a column of data
$ SQL = "select * from ec_admin ";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]);

Printf ("username: % s
", Mysql_result ($ result, 3," UserName "));
Printf ("Password: % s
", Mysql_result ($ result, 3," UserPass "));

?>

3. Insert a data entry

$ SQL = "insert into ec_admin (UserName, UserPass) values (liugongxun2, jakemary2 )";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]) or die (mysql_error ());

?>

4. while loop

$ SQL = "select * from ec_admin ";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]);
While ($ myrow = mysql_fetch_row ($ result ))
{
Printf ("username % s password
", $ Myrow [1], $ myrow [2]);
}

?>

5. do while loop

$ SQL = "select * from ec_admin ";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]);
If ($ myrow = mysql_fetch_array ($ result ))
{
Do
{
Printf ("username % s password
", $ Myrow [" UserName "], $ myrow [" UserPass "]);
} While ($ myrow = mysql_fetch_array ($ result ));
}
?>

6. determine whether the form is submitted.

If ($ submit)

{}

?>

Why? Php $ dbhost = localhost; $ dbuser = root; // your mysql username $ dbpass = 123456; // your mysql password $ dbname = data; // your mysql database name // connect to the local database...

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.