Home > Article > Backend Development > Basic introduction to asp.net MVC Several good example codes for getting started with PHP
1. PHP connects to the database
$dbhost = 'localhost';
$dbuser = 'root'; //Your mysql username
$dbpass = '123456'; //Your mysql password
$dbname = 'data'; //Your mysql library name
//Connect to the local database
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);
//Open the database
mysql_select_db($dbname, $GLOBALS["conn"]);
?>
2.php reads the value of a certain field in the database
//Reads a column of data
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
printf("Username: %s
n", mysql_result($result,3,"UserName"));
printf("Password : %s
n", mysql_result($result,3,"UserPass"));
?>
3,php insert a certain piece of data
$sql="insert into ec_admin(UserName, UserPass) values('liugongxun2','jakemary2')";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());
?>
4,php while loop
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
while($myrow = mysql_fetch_row($result))
{
printf( "Username %s %s password
",$myrow[1],$myrow[2]);
}
?>
5,php do while loop
$sql ="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
if($myrow = mysql_fetch_array($result))
{
do
{
printf("username %s %sPassword
",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow = mysql_fetch_array($result));
}
?>
6, php determines whether the form is submitted
if ($submit)
{}
?>
The above introduces some good example codes for basic introduction to asp.net MVC and basic introduction to PHP, including the basic introduction to asp.net MVC. I hope it will be helpful to friends who are interested in PHP tutorials.