php 连接mysql
程序员文章站
2022-05-02 08:31:09
...
$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);
?>