首页 >后端开发 >php教程 >入门:PHP与MYSQL的结合操作_PHP教程

入门:PHP与MYSQL的结合操作_PHP教程

WBOY
WBOY原创
2016-07-13 17:29:46811浏览

,连接数据库

$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.读取数据库中,某一字段值

//读取一列数据
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);

printf("用户名: %s
", mysql_result($result,3,"UserName"));
printf("密码: %s
", mysql_result($result,3,"UserPass"));

?>

3,插入某一条数据

$sql="insert into ec_admin(UserName,UserPass) values(liugongxun2,jakemary2)";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());

?>

4,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,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,判断表单是否提交

if ($submit)

{}

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/531667.htmlTechArticle,连接数据库 ?php $dbhost = localhost; $dbuser = root; //你的mysql用户名 $dbpass = 123456; //你的mysql密码 $dbname = data; //你的mysql库名 //连接本地数据库...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn