欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 连接mysql

程序员文章站 2024-02-12 09:57:22
...



新建网页




$link=@mysql_pconnect('127.0.0.1','root','');
mysql_select_db('mysql',$link);
$query="SELECT Host,User FROM user";
$result=mysql_query($query,$link);
//获取的字段
while($filed=mysql_fetch_field($result)){
echo $filed->name."
";

}
echo mysql_affected_rows($link);
//获取行
while($row=mysql_fetch_row($result)){
echo $row[0].$row[1].'
';
}

//$query="CREATE DATABASE my_db";
/*$sql = "CREATE TABLE Persons (
FirstName varchar(15),
LastName varchar(15),
Age int
)";*/
/*$sql = "CREATE TABLE Persons (personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int
)"; 设置主键
*/

/*mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");*/

/*$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "
";
}

*/
/*查找
$result = mysql_query("SELECT * FROM Persons
WHERE FirstName='Peter'");

while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "
";
}

*/
mysql_close($link);
?>

相关标签: php 连接mysql