PHP入门学习的几个不错的实例代码

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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="selectFromec_admin";
$result=MysqL_query($sql,$GLOBALS["conn"]); PRintf("用户名:%s
\n",MysqL_result($result,3,"UserName"));
printf("密码:%s
\n","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密码
",$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密码
",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow=MysqL_fetch_array($result));
}
?> 6,PHP判断表单是否提交 <?php if($submIT) {} ?>

脚本宝典总结

以上是脚本宝典为你收集整理的PHP入门学习的几个不错的实例代码全部内容,希望文章能够帮你解决PHP入门学习的几个不错的实例代码所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:实例实例