PHP connection MySQL DB instance

Source: Internet
Author: User
Now do the project needs PHP connection MySQL database, although learned before, but now basically forget, and then find the relevant data to solve the problem, the following small series of specific methods to share in the script home platform for everyone to learn

The specific code looks like this:

<?php//sets the character set header (' content-type:text/html; Charset=utf8 ');//Connection Database $link = mysql_connect ("localhost", "root", " 123456 "), if (! $link) {echo ' Database connection failed ...<br> '; exit (-1);} Else{echo "Database connection succeeded ...<br>";} Select a database as the default database mysql_select_db (' PHP_SJK ');//Execute SQL INSERT statement $sql = "INSERT INTO zh VALUES (NULL, ' Wang Jie ', ' 123456 ')"; $CR = Mysql_ Query ($sql);//Determine if Insert succeeded if (! $cr) {echo "Data insertion failed. <br> ";} Else{echo "Data insertion succeeded. <br> ";} Execute SQL query Statement $sql = "SELECT * from zh"; $CR = mysql_query ($sql);//Get the returned result set and loop output echo "data show:<br><br><br> "while ($a = mysql_fetch_row ($CR)) {echo" {$a [0]}--{$a [1]}--{$a [2]}<br> ";} Close database connection mysql_close ($link);? >

About PHP connection MySQL database code to introduce you so much, welcome to the collection, thank you!

Related Article

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.