Several methods for connecting php to mysql database

Source: Internet
Author: User
One php Tutorial every day. today I want to summarize several methods for connecting to the mysql database & amp; rdquo, I just learned something I just learned after setting up the php environment a year ago, but after studying it for so long, I was so silly to follow the php Tutorial manual.

One php Tutorial every day. today, I suddenly want to summarize several methods of "connecting to mysql database", something I just learned after setting up the php environment a year ago, but after learning for such a long time, it was silly to take photos.Php TutorialThis is the simplest and most common mysql connection method!

1. the simplest way


 

2. object-oriented mysqli (detailed tutorial)


 

3. pdo connection to mysql (detailed tutorial)


 Query ('select * from user') as $ row) {print_r ($ row) ;}$ db = null; // Close the database} catch (PDOException $ e) {echo $ e-> getMessage () ;}?>

4. connecting to mysql using ADODB (detailed tutorial)


 connect('localhost','root','','test');$conn->Execute("set names utf8");$res = $conn->Execute("select * from user");if (!$res){echo $conn->ErrorMsg();}else{var_dump($res);}?>

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.