分类: 数据库开发技术
2012-02-24 17:00:51
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
///数据库的断开
mysql_close($db);
///数据库的操作
//查询
$query = "SELECT * FROM user WHERE ";
//插入
$query = "INSERT INTO employees VALUES (2,'John','Roberts','45 There St , Townville','Telephonist');"
//删除
$query = "DELETE FROM employees WHERE age IS NULL";
//修改
$query = "UPDATE employees SET FROM WHERE";
Townville','Telephonist');"
//结果
$result = mysql_query($query);
if(!$result)
{
echo "Error!";
exit ;
}
$num_reslutlt = mysql_num_rows($result);
//获取当前系统时间
$AddTime = date("YmdHms");
///////////////////////////1. enroll.php 用户注册
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
//验证用户填写数据的合理性
trim($UserMb);
trim($UserPwd);
trim($PwdConfirm);
if(!$UserMb || !$UserPwd || !$PwdConfirm)
{
echo "Your have not enter your detail message";
exit;
}
if($UserPwd != $PwdConfirm)
{
echo "Confirm Password not correct to passworld" ;
exit;
}
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
//获取当前系统时间
$AddTime = date("YmdHms");
//插入
$query = "INSERT INTO user VALUES ('','".$UserMb."','".$UserPwd."','".$AddTime."');"
//结果
$result = mysql_query($query);
if($result)
{
///以下为成功后的相关操作
echo "Enroll Success!";
}
else
{
echo "Error!";
exit ;
}
///数据库的断开
mysql_close($db);
////////////////////////////////////////////用户验证代码示例
//判断用户名是否设置
if(!isset($PHP_AUTH_USER))
{
header("WWW-Authenticate:Basic realm="身份验证功能"");
header("HTTP/1.0 401 Unauthorized");
echo "身份验证失败,您无权共享网络资源!";
exit();
}
/*连接数据库*/
$db=mysql_connect("localhost","root","");
//选择数据库
mysql_select_db("XinXiKu",$db);
//查询用户是否存在
$result=mysql_query("SELECT * FROM user WHERE name='$PHP_AUTH_USER' AND password='$PHP_AUTH_PW'",$db);
if ($myrow = mysql_fetch_row($result))
{
//以下为身份验证成功后的相关操作
}
else
{
//身份验证不成功,提示用户重新输入
header("WWW-Authenticate:Basic realm="身份验证功能"");
header("HTTP/1.0 401 Unauthorized");
echo "身份验证失败,您无权共享网络资源!";
exit();
}
///////////////////////2 login.php 用户登陆
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
//验证用户填写数据的合理性
trim($UserMb);
trim($UserPwd);
if(!$UserMb || !$UserPwd )
{
echo "Your have not enter your detail message";
exit;
}
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
//查询用户是否存在
$query = "SELECT * FROM user WHERE name='$UserMb' AND password='$UserPwd'";
$result=mysql_query($query);
if ($myrow = mysql_fetch_row($result))
{
//以下为身份验证成功后的相关操作
}
else
{
//身份验证不成功,提示用户重新输入
header("WWW-Authenticate:Basic realm="身份验证功能"");
header("HTTP/1.0 401 Unauthorized");
echo "身份验证失败,您无权共享网络资源!";
exit();
}
///数据库的断开
mysql_close($db);
////////////////// 3. 管理员登录
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
//验证用户填写数据的合理性
trim($SysUser);
trim($SysUserPwd);
if(!$SysUser || !$SysUserPwd )
{
echo "Your have not enter your detail message";
exit;
}
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
//查询用户是否存在
$query = "SELECT * FROM sysuser WHERE SysUser='$SysUser' AND SysUserPwd='$SysUserPwd'";
$result=mysql_query($query);
if ($myrow = mysql_fetch_row($result))
{
//以下为身份验证成功后的相关操作
}
else
{
//身份验证不成功,提示用户重新输入
header("WWW-Authenticate:Basic realm="身份验证功能"");
header("HTTP/1.0 401 Unauthorized");
echo "身份验证失败,您无权共享网络资源!";
exit();
}
///数据库的断开
mysql_close($db);
/////////////////////// 4. 文字短信管理
/**********显示短信********************/
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
//查询文字短信
$query = "SELECT * FROM sms WHERE SmsType='$SmsType';
$result=mysql_query($query);
if ($myrow = mysql_fetch_row($result))
{
//以下为提取成功后的相关操作
}
else
{
echo "无记录!";
exit();
}
///数据库的断开
mysql_close($db);
/*************添加短信*****************************/
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
//获取当前系统时间
$AddTime = date("YmdHms");
//添加
$query = "INSERT INTO sms VALUES ('',$SmsType,$SmsContent,$AddTime)";
$result=mysql_query($query);
if ($myrow = mysql_fetch_row($result))
{
//以下为添加成功后的相关操作
}
else
{
echo "Add fail!";
exit();
}
///数据库的断开
mysql_close($db);
/*************删除*********************************/
$Host = "localhost";
$Database = "smsdb";
$DbaUser = "root";
$DbaPassword = "";
////数据库的连接
$db = mysql_pconnect($Host, $DbaUser,$DbaPassword);
if(!$db)
{
echo "Error: Could not connect to database.Please try again.";
exit;
}
//选择数据库
mysql_select_db($Database,$db);
//删除
$query = "DELETE FROM sms WHERE SmsId = $SmsId";
$result=mysql_query($query);
if ($myrow = mysql_fetch_row($result))
{
//以下为删除成功后的相关操作
}
else
{
echo "Delete fail!";
exit();
}
///数据库的断开
mysql_close($db);