Php connection to mysql instance code

Source: Internet
Author: User
This article uses the mysql_connect function of php to connect to the mysql database. The precondition is that the extensionphp_mysql in php. ini should be removed from the previous ";". the code is as follows :? Ph... this article uses the mysql_connect function of php to connect to the mysql database. in ini; extension = php_mysql, remove the previous ";". the code is as follows:

 

Connect to and select a database. the code is as follows:

 

In this way, you can connect to the database. if you encounter problems, the following code appears: Call to undefined function 'MySQL _ connect ()'... Failed. the prompt "function undefined" indicates that the mysql_connect () function is not available.

The solution is as follows:

Run php_mysql.dll and libmysql. copy the dll file to c: winntsystem32 (I missed libmysql. dll), find php. in ini; extension = php_mysql, remove the previous ";" restart the server.

Now everything is ready. now we have a simple connection instance. for example 1, the code of the conn. php file is as follows:

 

The index. php file code is as follows:

 // Display data content:
  
 

In this way, we implement a simple php mysql connection and query the data we need.


Article address:

Reprint at will ^ please include the address of this 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.