白云岛资源网 Design By www.pvray.com
1,php连接数据库
<?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读取数据库中,某一字段值
<?php
//读取一列数据
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
printf("用户名: %s<br>\n", mysql_result($result,3,"UserName"));
printf("密码: %s<br>\n", mysql_result($result,3,"UserPass"));
?>
3,php插入某一条数据
<?php
$sql="insert into ec_admin(UserName,UserPass) values('liugongxun2','jakemary2')";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());
?>
4,php while循环
<?php
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
while($myrow = mysql_fetch_row($result))
{
printf("用户名%s %s密码<br />",$myrow[1],$myrow[2]);
}
?>
5,php do while循环
<?php
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
if($myrow = mysql_fetch_array($result))
{
do
{
printf("用户名%s %s密码<br />",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow = mysql_fetch_array($result));
}
?>
6,php判断表单是否提交
<?php
if ($submit)
{}
?>
<?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读取数据库中,某一字段值
<?php
//读取一列数据
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
printf("用户名: %s<br>\n", mysql_result($result,3,"UserName"));
printf("密码: %s<br>\n", mysql_result($result,3,"UserPass"));
?>
3,php插入某一条数据
<?php
$sql="insert into ec_admin(UserName,UserPass) values('liugongxun2','jakemary2')";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());
?>
4,php while循环
<?php
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
while($myrow = mysql_fetch_row($result))
{
printf("用户名%s %s密码<br />",$myrow[1],$myrow[2]);
}
?>
5,php do while循环
<?php
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
if($myrow = mysql_fetch_array($result))
{
do
{
printf("用户名%s %s密码<br />",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow = mysql_fetch_array($result));
}
?>
6,php判断表单是否提交
<?php
if ($submit)
{}
?>
白云岛资源网 Design By www.pvray.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
白云岛资源网 Design By www.pvray.com
暂无评论...