|
<?php
$dbhost = 'localhost';
$dbuser = 'root'; //你的mysql用戶名
$dbpass = '123456'; //你的mysql密碼
$dbname = 'data'; //你的mysql庫名
//連接本地數(shù)據(jù)庫
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);
//打開數(shù)據(jù)庫
mysql_select_db($dbname,$GLOBALS["conn"]);
?>
2.php讀取數(shù)據(jù)庫中,某一字段值
<?php
//讀取一列數(shù)據(jù)
$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插入某一條數(shù)據(jù)
<?php
$sql="insert into ec_admin(UserName,UserPass) values('liugongxun2','jakemary2')";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());
?>
4,php while循環(huán)
<?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循環(huán)
<?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技術(shù):PHP入門學(xué)習(xí)的幾個不錯的實例代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。