php连接mysql数据库

<?php


/**
 * @author minguanghui
 * @copyright 2012
 */
//Êý¾Ý¿âÁ¬½Ó
$con=mysql_connect("localhost","root","root");
if(!$con){
    die('Could not connect: '.mysql_error()."<br>");
}


/*
//´´½¨Êý¾Ý¿â
if(mysql_query("create database my_db",$con)){//×¢ÒâÊéд¸ñʽ
    echo "Database created.<br>";
}else{
    echo "Create database failed: ".mysql_error()."<br>";
}
*/


//Êý¾Ý¿âÑ¡Ôñ
mysql_select_db("my_db",$con);


/*
//´´½¨±í
$sql="create table test(
id int(10) not null AUTO_INCREMENT,
name varchar(50) default null,
age int(10) default null,
tel varchar(50) default null,
address varchar(50) default null,
primary key(id)
)";
mysql_query($sql,$con);
*/

//²åÈëÊý¾Ý
mysql_query("insert into test values(1,'°¡°¡°¡°¡°¡',23,'1111111111111','±±¾©º£µí')");
mysql_query("insert into test values(2,'µ­µ­µÄµ­µ­µÄµ­µ­µÄ',12,'222222222222','ÉϺ£ÆÖ¶«')");
//¹Ø±ÕÊý¾Ý¿â
mysql_close($con);
print "mysql connnection.<br>";

$site="http://www.baidu.com";
fopen($site,"r") or die("Unable to connect $site<br>");
print "site open.<br>";
?>

你可能感兴趣的:(php连接mysql数据库)