Yojo网页设计

首页 新闻中心 网页教程 图形图像 设计欣赏 编程开发 程序教程 网站运营 数据库教程
·ASP教程·ASP.net教程·PHP教程·JSP教程·编程杂谈·AJAX·XML

您现在的位置: yojo网页设计 >> 编程开发 >> PHP教程 >> 正文

 

PHP与MYSQL的结合操作

更新时间:2007-11-18 9:37:54 文章来源:互联网 .

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<br>\n", mysql_result($result,3,"UserName"));
printf("密码: %s<br>\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,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,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

if ($submit)

{}

?>


点击: 文章地址:http://www.518web.net/bckf/php/2351.html

热门点击

友情链接首页文字链接要求:PR≥4,搜索引擎正常收录,开通一年以上,内容健康充实的站点!申请...

Copyright(C) 2005-2008 518web.net,All Rights Reserve
Email:yojo.x@msn.com | 在线QQ:2306380 53614197| [浙ICP备08009643号]