当前位置: 首页 > 图文教程 > 网络编程 > PHP > 一个对数据库进行操作的程序

PHP
PHP技巧:详解phplib模板使用过程及运行原理
PHP技巧:Smarty+adodb分页示例
PHP技巧:PHP脚本中关于拼写检查函数库
PHP技巧:PHP脚本编程中的文件系统函数库
PHP技巧:PHP中几种删除目录的三种方法
学习PHP技术:txtSQL安装手册中文版
学习PHP:PHP的通用检测函数总结
详细学习PHP中对文件和目录的操作方法
PHP+MYSQL实例:网站在线人数的程序代码
Linux操作系统启动httpd失败的解决方法
初学:在PHP开发中如何使用Session?
PHP初学者遇到的中文乱码解决方案
PHP实例:实现文件上传的程序源码
PHP实例:常用的数值判断函数
PHP实例源代码:PHP实现翻页处理的类
PHP实例:从数组里筛选出重复的数据
PHP实例:用PHP实现windows风格的树型菜单
PHP实例程序:实现给上传图片加水印图案的做法
PHP实例:用PHP编写的网上调查投票系统
PHP实例:一个非常全面获取图象信息的PHP函数

PHP 中的 一个对数据库进行操作的程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 86 ::
收藏到网摘: n/a

db.func:

<?
functionGetRows($Database,$Query){
mysql_connect("ftp","root","");
$db=mysql_select_db($Database);
if(!$db){
echo"无法连结数据库!";
exit;
}

$rows=mysql_query($Query);
if(!$rows){
echo"SQL指令错误!";
exit;
}
return$rows;
}

functionConnectDatabase($Database){
mysql_connect("ftp","root","");
$db=mysql_select_db($Database);
if(!$db){
echo"无法连结数据库!";
exit;
}
}
?>

cratetable.php:

<?
functionCreateTable(){
$link=mysql_connect("ftp","root","");
$db=mysql_select_db("pcadmin");
if(!$db){
echo"连接到数据库失败!";
exit;
}
$rows=mysql_query("select*fromProfile");
if(!$rows){
$sql="CreateTableProfile(IDintegerauto_incrementprimarykey,Namechar(255),Producechar(255),Lianluochar(255),Telinteger(15),Emailchar(255))";
mysql_query($sql);
}

$rows=mysql_query("select*fromAplication");
if(!$rows){
$sql="CreateTableAplication(Namechar(255)primarykey,IPchar(255),Apchar(255),Directorychar(255))";
mysql_query($sql);
}
mysql_close($link);
}
CreateTable();
?>

input.htm:

<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title>輸入表單</title>
<styletype="text/css">
<!--
.INPUT{
border:1pxsolid#003C74;
}
.font{
font-family:"新宋体";
font-size:14px;
color:#0000FF;
font-weight:lighter;
}
.table{
border:1pxsolid#000000;
}
.title{
font-family:"新宋体";
font-size:14px;
color:#FF0000;
}
-->
</style>
</head>

<body><h3><centerclass="title">輸入表單
</center><hrsize="1"noshade>
</h3>

<formname="form1"method="post"action="insert.php">
<tablewidth="400"align=center>
<tr>
<thscope="row"><divalign="left"class="font">主機名稱</div></th>
<td><inputname="Name"type="text"class="input"></td>
</tr>
<tr>
<thscope="row"><divalign="left"class="font">生產廠商</div></th>
<td><inputname="Produce"type="text"class="INPUT"></td>
</tr>
<tr>
<thscope="row"><divalign="left"class="font">聯絡人</div></th>
<td><inputname="Lianluo"type="text"class="INPUT"></td>
</tr>
<tr>
<thscope="row"><divalign="left"class="font">聯絡人電話</div></th>
<td><inputname="Tel"type="text"class="INPUT"></td>
</tr>
<tr>
<thscope="row"><divalign="left"class="font">聯絡人郵箱</div></th>
<td><inputname="Email"type="text"class="INPUT"></td>
</tr>
<tr>
<thscope="row"><palign="left"class="font">IP Address</p>
</th>
<td><inputname="IP"type="text"class="INPUT"></td>
</tr>
<tr>
<thscope="row"><divalign="left"class="font">應用名稱</div></th>
<td><inputname="Ap"type="text"class="INPUT"></td>
</tr>
<tr>
<thalign="left"valign="top"scope="row"><divalign="left"class="font">配置文件</div></th>
<td><textareaname="Directory"cols="40"rows="5"class="INPUT"clums="15"></textarea></td>
</tr>
<tr>
<thscope="row"><inputname="Send"type="submit"class="INPUT"value="提交"></th>
<td><inputname="Submit"type="reset"class="INPUT"value="重寫">
<ahref="show.php">查看记录</a></td>
</tr>
</table>

</form><hrsize="1"noshade>
<p>&nbsp;</p>
</body>
</html>

insert.php:

<HTML>
<styletype="text/css">
<!--
.font{
font-family:"新宋体";
font-size:14px;
font-weight:lighter;
color:#FF0000;
}
-->
</style>
<BODYbgcolor="#FFFFFF">
<H3><ahref="show.php"class="font">成功輸入一筆資料去看看</a>
<HR></H3>
<?
include("../db.func");

if(!empty($Send)){
ConnectDatabase("pcadmin");
$sql="insertintoProfile(Name,Produce,Lianluo,Tel,Email)values('$Name','$Produce','$Lianluo','$Tel','$Email')";

mysql_query($sql);
}
?>
</BODY>
</HTML>

show.php:

<?
functionShowOnePage($rows,$No){
mysql_data_seek($rows,$No);

echo"<TABLEBorder=1Align=Centerbordercolordark='#ffffff'bordercolorlight='#000000'cellpadding='3'cellspacing='0'>";
echo"<TRBgColor=Cyan>";
while($field=mysql_fetch_field($rows)){
echo"<TD>".$field->name."</TD>";
}
echo"</TR>";
$nums=mysql_num_rows($rows);
for($I=1;$I<=10;$I++){
if($row=mysql_fetch_row($rows)){
for($K=0;$K<count($row);$K++){
echo"<TDAlign=Right>".$row[$K]."</TD>";
}
echo"</TR>";
}
}
echo"</TABLE>";
}
?>

<HTML>
<styletype="text/css">
<!--
.title{
color:#FF0000;
font-family:"新宋体";
font-size:14px;
}
.body{
font-family:"新宋体";
font-size:12px;
font-weight:lighter;
color:#0000FF;
}
-->
</style>
<title>伺服器清单</title><BODYbgcolor="#FFFFFF">
<H2ALIGN=CENTER><spanclass="title">伺服器清單</span>
<HRsize="1"noshadecolor="#0000ff"class="hr">
</H2>
<?
include("../db.func");
$rows=GetRows("pcadmin","Select*FromProfile");

$num=mysql_num_rows($rows);
$Pages=intval(($num-1)/10)+1;

if($Page<1)$Page=1;
if($Page>$Pages)$Page=$Pages;

ShowOnePage($rows,($Page-1)*10);
?>
<HRsize="1"noshadecolor="#0000ff"class="hr">
<FORMAction=<?echo$PHP_SELF;?>Method=GET>
<DIVAlign=right>
<?
if($Page<>1){//