PHP connection MySQL database, phpmysql database _php Tutorial

Source: Internet
Author: User

PHP connection MySQL database, phpmysql database


Because the first two days a project needs PHP to connect to MySQL, although previously learned, but now basically forgot all about it, but later found a lot of information to find the method:

 Php//Set character sets    Header(' content-type:text/html; Charset=utf8 '); //connecting to a database    $link=mysql_connect("localhost", "root", "123456"); if(!$link){        Echo' Database connection failed ...
'; Exit(-1); }Else{ Echo"Database connection succeeded ...
"; } //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.
"; }Else{ Echo"Data insertion succeeded.
"; } //Execute SQL query statement $sql= "SELECT * from en"; $CR=mysql_query($sql); //gets the returned result set, and loops the output Echo"Data show:


"; while($a=Mysql_fetch_row($CR)){ Echo"{$a[0]} ——{$a[1]} ——{$a[2]}
"; } //To close a database connection Mysql_close($link);?>

http://www.bkjia.com/PHPjc/1093868.html www.bkjia.com true http://www.bkjia.com/PHPjc/1093868.html techarticle PHP connection MySQL database, Phpmysql database because the first two days a project needs PHP connection MySQL, although previously learned, but now basic also forget, but later find a lot of capital ...

  • 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.