PHP connection to MYSQL database instance code, phpmysql database instance _ PHP Tutorial

Source: Internet
Author: User
PHP connects to the MYSQL database instance code and phpmysql database instance. PHP connects to the MYSQL database instance code. The current project of the phpmysql database instance requires php to connect to the mysql database. although I have learned it before, I almost forgot it now, then, you can check the PHP code used to connect to the MYSQL database instance.

The current project requires php to connect to the mysql database. although I have learned it before, I almost forgot it now. then I found a solution by searching for relevant information, the following small series will share the specific methods on the help house platform for everyone to learn.

The code is as follows:

<? Php // set the character set header ('content-Type: text/html; charset = utf8'); // connect to the database $ link = mysql_connect ("localhost", "root ", "123456"); if (! $ Link) {echo 'database connection failed...
'; Exit (-1);} else {echo "database connection successful...
";}// Select a database as the default database mysql_select_db ('php _ sjk'); // execute the SQL INSERT statement $ SQL =" INSERT INTO zh VALUES (NULL, 'Wang jie', '000000') "; $ cr = mysql_query ($ SQL); // you can determine whether the data is successfully inserted if (! $ Cr) {echo "data insertion failed.
";} Else {echo" data is inserted successfully.
";}// Run the SQL query statement $ SQL =" select * from zh "; $ cr = mysql_query ($ SQL); // Obtain the returned result set, and cyclically output echo "data display:


"; While ($ a = mysql_fetch_row ($ cr) {echo" {$ a [0]} -- {$ a [1]} -- {$ a [2]}
";}// Close the database connection mysql_close ($ link);?>

The code for connecting PHP to the MYSQL database is described so much. you are welcome to add it to your favorites. thank you!

Articles you may be interested in:
  • Php connection to mysql database code
  • Mysql undefined function mysql_connect () is prompted When PHP is connected to the database under IIS ()
  • Php cannot connect to the database php error Can't connect to local MySQL server
  • Php entry-a class connecting to the mysql database
  • How to connect to the database after mysqli extension is enabled in php
  • Simple example of connecting MYSQL database in the LAN using PHP
  • Sample code for connecting multiple mysql databases in PHP at the same time
  • Connect to the mysql database and query data based on php
  • Common Php code for connecting to, reading, and writing to the mysql database
  • Basic tutorial on connecting to and operating MySQL databases using PHP
  • Comparison and analysis of database connection methods pdo and mysqli in php

Ghost's current project requires php to connect to the mysql database. although I have learned it before, I basically forgot it now. then I checked it...

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.