asp.net MVC基础入门 PHP入门学习的几个不错的实例代码
程序员文章站
2022-04-19 21:10:24
...
1,php连接数据库
$dbhost = 'localhost';
$dbuser = 'root'; //你的mysql用户名
$dbpass = '123456'; //你的mysql密码
$dbname = 'data'; //你的mysql库名
//连接本地数据库
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);
//打开数据库
mysql_select_db($dbname,$GLOBALS["conn"]);
?>
2.php读取数据库中,某一字段值
//读取一列数据
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
printf("用户名: %s
\n", mysql_result($result,3,"UserName"));
printf("密码: %s
\n", mysql_result($result,3,"UserPass"));
?>
3,php插入某一条数据
$sql="insert into ec_admin(UserName,UserPass) values('liugongxun2','jakemary2')";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());
?>
4,php while循环
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
while($myrow = mysql_fetch_row($result))
{
printf("用户名%s %s密码
",$myrow[1],$myrow[2]);
}
?>
5,php do while循环
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
if($myrow = mysql_fetch_array($result))
{
do
{
printf("用户名%s %s密码
",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow = mysql_fetch_array($result));
}
?>
6,php判断表单是否提交
if ($submit)
{}
?>
$dbhost = 'localhost';
$dbuser = 'root'; //你的mysql用户名
$dbpass = '123456'; //你的mysql密码
$dbname = 'data'; //你的mysql库名
//连接本地数据库
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);
//打开数据库
mysql_select_db($dbname,$GLOBALS["conn"]);
?>
2.php读取数据库中,某一字段值
//读取一列数据
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
printf("用户名: %s
\n", mysql_result($result,3,"UserName"));
printf("密码: %s
\n", mysql_result($result,3,"UserPass"));
?>
3,php插入某一条数据
$sql="insert into ec_admin(UserName,UserPass) values('liugongxun2','jakemary2')";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());
?>
4,php while循环
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
while($myrow = mysql_fetch_row($result))
{
printf("用户名%s %s密码
",$myrow[1],$myrow[2]);
}
?>
5,php do while循环
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
if($myrow = mysql_fetch_array($result))
{
do
{
printf("用户名%s %s密码
",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow = mysql_fetch_array($result));
}
?>
6,php判断表单是否提交
if ($submit)
{}
?>
以上就介绍了asp.net MVC基础入门 PHP入门学习的几个不错的实例代码,包括了asp.net MVC基础入门方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: 快乐男声学院24小时 php GD绘制24小时柱状图
下一篇: php压缩和解压缩字符串的代码