当前位置:Gxlcms > PHP教程 > php连接mysql

php连接mysql

时间:2021-07-01 10:21:17 帮助过:36人阅读




新建网页




$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);
?>

人气教程排行