1.
Copy code The code is as follows:
$connection=mysql_connect("localhost","root","password"); //Connect and select the database server
mysql_select_db("test",$connection) ;
$query="insert into users(user_name)"; //Insert a piece of data in the test database
$query.="values('tuxiaohui')";
$result=mysql_query($ query);
if(!$query)
echo "insert data failed!
";
else{
$query="select * from users"; //Query data
$result=mysql_query($query,$connection);
for($rows_count=0;$rows_count<7;$rows_count++) //Use mysql_result to obtain data and output, mysql_result() returns a unit in the MySQL result set content.
{
echo "User ID:".mysql_result($result,$rows_count,"user_id")."
";
echo "User name:".mysql_result($result,$ rows_count,"user_name")."
";
}
}
?>
2.
Copy code The code is as follows:
$connection=mysql_connect("localhost","root","password"); //Connect and select the database server
mysql_select_db("test",$connection);
$ query="select * from users";
$result=mysql_query($query,$connection);
while($row=mysql_fetch_row($result))
{
echo "User ID: ".$row[0]."
";
echo "Username: ".$row[1]."
";
}
?>
3.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn