How to access MySQL with PHP statements

Source: Internet
Author: User
Tags mysql insert

<?PHP//The encoding of the set character is utf-8, which resolves the Chinese in the URLHeader("content-type:text/html; Charset=utf8 "); //get the variables in the browser URL$dbdatabase=$_get[dbdatabase];$tablename=$_get[TableName];//MySQL account password$dbhost= "localhost";$username= "Root";$userpass= "123456";//Connect to MySQL$link=mysql_connect($dbhost,$username,$userpass); if(!$link) {     die(' Could not connect: '.Mysql_error());}Echo' Connected successfully ';Echo"<br>";mysql_select_db($dbdatabase,$link) or die(' Could not select Database. '));//MySQL Query statement$sql= "SELECT * from".$tablename;//MySQL INSERT statement$ins= "INSERT INTO".$tablename. "VALUES (' 5 ', ' thgf ', ' noon ', ', ', ')";//Execute INSERT statementmysql_query("Set Names UTF8");mysql_query($ins);//executes the execution statement to get the data in the databasemysql_query("Set Names UTF8");$result=mysql_query($sql,$link);Echo $result;Echo"<br>";//output What to look for while($row=Mysql_fetch_row($result)){        foreach($row  as $val){            Echo‘--‘.$val; }                Echo' <br/> '; }    //4. Close Resources    $row-Free (); Mysql_close();?>

How to access MySQL with PHP statements

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.