PHP MySQL Connection Database

Source: Internet
Author: User
Tags php mysql

PHP connection to MySQL small instance

<?php
/*Date: 2014-09-14
* Gechong
* Function: PHP connection MySQL Small instance
* */
/*
SQL scripts. Paste directly to the command line to run.

DROP DATABASE Gechong;
CREATE DATABASE Gechong;
Use Gechong
CREATE TABLE T1 (
ID INT (10),
Name VARCHAR (10),
URL VARCHAR (30));

INSERT into T1 VALUES (1, ' gechong1 ', ' http://www.cnblogs.com/xiaoit/');
INSERT into T1 VALUES (2, ' gechong2 ', ' http://www.cnblogs.com/xiaoit/');
INSERT into T1 VALUES (3, ' gechong3 ', ' http://www.cnblogs.com/xiaoit/');
INSERT into T1 VALUES (4, ' Gechong4 ', ' http://www.cnblogs.com/xiaoit/');
INSERT into T1 VALUES (5, ' gechong5 ', ' http://www.cnblogs.com/xiaoit/');

*/
$con=mysql_connect("localhost", "root", "Gechong");
if(!$con)
{
die(' Could not connect: '.Mysql_error());
}

mysql_select_db("Gechong",$con);

$result=mysql_query("SELECT * from T1");

Echo"<table border= ' 3 ' >
<tr>
<th bgcolor= #FF0000 >ID</th>
<th bgcolor= #FF0000 >Name</th>
<th bgcolor= #FF0000 >URL</th>
</tr> ";

while($row=Mysql_fetch_array($result))
{
Echo"<tr>";
Echo"<td >".$row[' ID ']. "</td>";
Echo"<td >".$row[' Name ']. "</td>";
Echo"<td >".$row[' URL ']. "</td>";
Echo"</tr>";
}
Echo"</table>";

Mysql_close($con);

?>

PHP MySQL Connection Database

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.