Php connection to mysql-php Tutorial

Source: Internet
Author: User
Php connection to mysql


Create Web Page




$ Link = @ mysql_pconnect ('2017. 0.0.1 ', 'root ','');
Mysql_select_db ('mysql', $ link );
$ Query = "SELECT Host, User FROM user ";
$ Result = mysql_query ($ query, $ link );
// The obtained field
While ($ filed = mysql_fetch_field ($ result )){
Echo $ filed-> name ."
";

}
Echo mysql_affected_rows ($ link );
// Obtain the row
While ($ row = mysql_fetch_row ($ result )){
Echo $ row [0]. $ row [1].'
';
}

// $ Query = "create database my_db ";
/* $ SQL = "CREATE TABLE Persons (
FirstName varchar (15 ),
LastName varchar (15 ),
Age int
)";*/
/* $ SQL = "CREATE TABLE Persons (personID int NOT NULL AUTO_INCREMENT,
Primary key (personID ),
FirstName varchar (15 ),
LastName varchar (15 ),
Age int
) "; Set the primary key
*/

/* Mysql_query ("insert into Persons (FirstName, LastName, Age)
VALUES ('Peter ', 'Griffin', '35 ')");*/

/* $ Result = mysql_query ("SELECT * FROM Persons ");

While ($ row = mysql_fetch_array ($ result ))
{
Echo $ row ['firstname']. "". $ row ['lastname'];
Echo"
";
}

*/
/* Search
$ Result = mysql_query ("SELECT * FROM Persons
WHERE FirstName = 'Peter '");

While ($ row = mysql_fetch_array ($ result ))
{
Echo $ row ['firstname']. "". $ row ['lastname'];
Echo"
";
}

*/
Mysql_close ($ link );
?>

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.