手机
当前位置:查字典教程网 >编程开发 >php教程 >PHP入门学习的几个不错的实例代码
PHP入门学习的几个不错的实例代码
摘要:1,php连接数据库2.php读取数据库中,某一字段值3,php插入某一条数据

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*fromec_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="insertintoec_admin(UserName,UserPass)values('liugongxun2','jakemary2')";

$result=mysql_query($sql,$GLOBALS["conn"])ordie(mysql_error());

?>

4,php while循环

<?php

$sql="select*fromec_admin";

$result=mysql_query($sql,$GLOBALS["conn"]);

while($myrow=mysql_fetch_row($result))

{

printf("用户名%s%s密码<br/>",$myrow[1],$myrow[2]);

}

?>

5,php dowhile循环

<?php

$sql="select*fromec_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入门学习的几个不错的实例代码】相关文章:

文件上传的实现

PHP中的命名空间详细介绍

关于PHP中的Class的几点个人看法

PHP 中的一些经验积累

PHP编译安装时常见错误解决办法

PHP学习之PHP运算符

JAVA/JSP学习系列之五

PHP5在Apache下的两种模式的安装

PHPlet在Windows下的安装

PHP的FTP学习(一)[转自奥索]

精品推荐
分类导航