How to query MySQL Data in php

Source: Internet
Author: User

The following article describes how to use php to query MySQL Data. This document describes how to use php to query MySQL Data, the following is a detailed description of the article. I hope you will have a better understanding of it.

 
 
  1. <?php 
  2. $link = mysql_connect('localhost', 'root', '123456')  
  3. or die('Could not connect: ' . mysql_error());  
  4. mysql_select_db('ruida') or die('Could not select database'); 

Execute SQL query

 
 
  1. $query = 'SELECT * FROM product';  
  2. $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 

Display Results in HTML

 
 
  1. echo "<table>\n";  
  2. while ($line = mysql_fetch_assoc($result)) {  
  3. echo "\t<tr>\n";  
  4. foreach ($line as $col_value) {  
  5. echo "\t\t<td>$col_value</td>\n";  
  6. }  
  7. echo "\t</tr>\n";  
  8. }  
  9. echo "</table>\n"; 

Release result set

 
 
  1. mysql_free_result($result); 


 

Close connection

 
 
  1. mysql_close($link);  
  2. ?>  

The above content is an introduction to querying MySQL Data in php. I hope you will find some gains.
 

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.