安卓版php服务器的mysql数据库增删改查简单案例
界面:
index.php文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>手机网站主页</title>
<style type="text/css">
body{margin:0px;padding:0px;font-size:40px;}
.box{width:800px;height:1100px;border:solid 2px #808080;margin:80px auto 10px auto;}
ul{margin:60px 50px; list-style-type:none;}
h2{text-align:center;}
.textStyle{color:red;}
.a_under{float:left;margin:5px 0px 0px 250px;}
</style>
</head>
<body>
<h2>手机网站主页</h2>
<div class="box">
<ul>
<li><a href="phpinfo.php" target="_blank" >php信息</a></li>
<li> </li>
<li> </li>
<li><a href="mysqlRead.php" target="_blank" >数据库读取(mysqlRead.php)</a></li>
<li><a href="mysqlEdit.php" target="_blank" >数据库操作(mysqlEdit.php)</a></li>
<li><a href="http://localhost:8080/phpMyAdmin" target="_blank" >phpMyAdmin数据库管理</a></li>
<li> </li>
<li> </li>
<li><p class="textStyle">首次打开此页时,首先点击"创建数据库";然后点击"创建数据表";最后不可轻易操作以下内容,操作以下内容会影响数据库的结构!</p></li>
<li><a href="createDatabase.php" onclick="event.returnValue=confirm('确定创建数据库吗?')
">创建数据库</a></li>
<li><a href="createTable.php" onclick="event.returnValue=confirm('确定创建数据表吗?')
">创建数据表</a></li>
<li><a href="dropTable.php" onclick="event.returnValue=confirm('确定删除数据表吗?')
">删除数据表</a></li>
</ul>
</div>
<a href="http://alfanla.com/palapa-web-server/" target="_blank" class="a_under">帕垃帕安卓php服务器软件</a>
</body>
</html>
mysqlRead.php文件:
<?php
/**
*mysql数据库读取
*/
include_once('function.class.php');
$sql = 'select * from pw_luck';
$title = 'Mysql数据库全部内容';
show_mysql($sql, $title); ?>
mysqlEdit.php文件:
<?php /*
*mysql数据库的增删改查操作。
*/
header("content-type:text/html;charset=utf-8"); $ID = @$_POST['userId'];
$name = @$_POST['userName'];
$age = @$_POST['userAge'];
$intro = @$_POST['userIntro'];
include_once ('mysqlAccount.php');
$conn = mysql_connect(constant("HOST"), constant("userName"), constant("password"));
mysql_query("set names 'utf8'");
mysql_select_db(constant("database_db")); if (@$_POST['add'] == '增加') { /*添加数据*/ $sql = "insert into pw_luck values ($ID,'$name',$age,'$intro');";
if (!mysql_query($sql, $conn)) {
$err = mysql_error(); echo ('错误:' . mysql_error() . "<script>var err=\"$err\";alert('错误:' + err);location.href='mysqlEdit.php'</script>"); }
mysql_close($conn); } if (@$_POST['modify'] == "修改") { /*修改数据*/
$sql = "select id from pw_luck where id=$ID";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array($result);
if ($row['id'] <> $ID) {
echo "<script>alert('修改的数据ID值不在数据库的范围内,修改没有成功!')</script>";
}
mysql_free_result($result);
$sql = "update pw_luck set name='$name',age=$age,intro='$intro' where id=$ID;"; if (!mysql_query($sql, $conn)) { die('错误: ' . mysql_error() . "<br/><br/><a href='mysqlEdit.php'>返回重新输入</a>");
} mysql_close($conn);
} if (@$_POST['delet'] == "删除") { /*删除数据*/
$sql = "delete from pw_luck where id=$ID;"; if (!mysql_query($sql, $conn)) { die('错误: ' . mysql_error() . "<br/><br/><a href='mysqlEdit.php'>返回重新输入</a>");
} mysql_close($conn);
} if (@$_POST['select'] == "查询") { /*查询数据库*/
include_once('function.class.php');
$ID_sql = "id='$ID'";
/*注意:这里只能用双引号,否则查询时出错,并且变量必须用单引号括起来!*/
$name_sql = "name LIKE '%$name%'";
$age_sql = "age='$age'";
$intro_sql = "intro LIKE '%$intro%'";
if ($ID == '' or $ID == 'NULL')
$ID_sql = true;
if ($name == '')
$name_sql = true;
if ($age == '')
$age_sql = true;
if ($intro == '')
$intro_sql = true;
$sql = "select * from pw_luck where $ID_sql AND $name_sql AND $age_sql AND $intro_sql;";
//echo $sql; /*检查sql语句的格式是否正确*/
$title='Mysql数据库查询结果';
show_mysql($sql,$title);
exit();
/*查询时截断下面的脚本显示,不显示下面的界面*/
}
?>
<!-------下面是界面代码,上面是后台处理代码------->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Mysql数据库操作</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function addtext(){
event.returnValue=confirm("确定增加数据吗?");
if(event.returnValue){
if(document.getElementById("userId").value==""){
alert("ID不能为空,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("name").value==""){
alert("姓名不能为空,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("age").value==""){
alert("年龄不能为空,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("age").value==0){
alert("年龄不能为0岁,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("age").value>100){
alert("年龄不能超过100岁,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("intro").value==""){
event.returnValue=confirm("你确定不需要给此人一个简介吗?");
}
}
}
function modifytext(){
event.returnValue=confirm("确定修改数据吗?");
if(event.returnValue){
var idValue=document.getElementById("userId").value;
if(idValue=="" || idValue=="NULL"){
alert("修改数据是基于ID值来判断的,因此ID值不能为空或为NULL!");
event.returnValue=false;
}else if(document.getElementById("name").value==""){
alert("姓名不能为空,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("age").value==""){
alert("年龄不能为空,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("age").value==0){
alert("年龄不能为0岁,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("age").value>100){
alert("年龄不能超过100岁,请重新输入!");
event.returnValue=false;
}else if(document.getElementById("intro").value==""){
event.returnValue=confirm("你确定不需要给此人一个简介吗?");
}
}
}
function delettext(){
var idValue=document.getElementById("userId").value;
event.returnValue=confirm("确定删除数据吗?");
if(event.returnValue){
if(idValue=="" || idValue=="NULL"){
alert("删除数据是基于ID值来判断的,因此ID值不能为空或为NULL,其它不用填写!");
event.returnValue=false;
}
}
}
function selecttext(){
event.returnValue=confirm("确定查询数据吗?");
}
</script>
<style type="text/css">
body{font-size:150%;}
.box{border:solid 1px #808080;width:900px;height:900px; margin:100px auto;background:#5F9EA0;border-radius:30px;}
h1{text-align:center;font-size:320%;}
table.tb{width:100%;height:800px;font-size:50px;margin-top:50px;}
input{width:90%;height:80px;font-size:50px;}
.left{text-align:right;width:200px;}
.inp{background:#9932CC;}
.inp:hover{background:#D2691E;}
a{font-size:50px;}
table.tb_out{margin:40px auto;text-align:center;font-size:24px;border-collapse:collapse;}
.box_out{width:100%;height:1200px;border:solid 1px #808080;}
th{background:#5f9ea0;}
.text_color{background:#ADD8E6;}
.text_color_1{background:#E0FFFF;}
</style>
</head>
<body>
<h1>Mysql数据库操作</h1>
<div class="box">
<form action="" name="formPage" method="POST">
<table border="0" class="tb">
<tr>
<td class="left">ID:</td>
<td><input type="text" name="userId" id="userId" value="NULL" onfocus="javascript:if(this.value=='NULL')this.value='';" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
</tr>
<tr>
<td class="left">姓名:</td>
<td><input type="text" name="userName" id="name"></td>
</tr>
<tr>
<td class="left">年龄:</td>
<td><input type="text" name="userAge" id="age" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
</tr>
<tr>
<td class="left">简介:</td>
<td><input type="text" name="userIntro" id="intro"></td>
</tr>
<tr>
<td></td>
<td><input class="inp" type="submit" name="add" value="增加" onclick="addtext()"></td>
</tr>
<tr>
<td></td>
<td><input class="inp" type="submit" name="modify" value="修改" onclick="modifytext()"></td>
</tr>
<tr>
<td></td>
<td><input class="inp" type="submit" name="delet" value="删除" onclick="delettext()"></td>
</tr>
<tr>
<td></td>
<td><input class="inp" type="submit" name="select" value="查询" onclick="selecttext()"></td>
</tr>
</table>
</form>
</div>
<a href="mysqlRead.php">Mysql数据库读取</a>
<a href="index.php" style="float:right;">返回主页</a>
</body>
</html>
function.class.php文件:
<?php
/**
* mysql数据库显示函数
*/ function show_mysql($sql, $title) {
// echo $sql; /*检查sql语句的格式是否正确*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php echo $title ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body{}
h1{text-align:center;}
table{margin:40px auto;text-align:center;font-size:24px;border-collapse:collapse;}
.box{width:100%;height:1200px;border:solid 1px #808080;}
th{background:#5f9ea0;}
a{font-size:36px;}
.text_color{background:#ADD8E6;}
.text_color_1{background:#E0FFFF;}
</style>
</head>
<body>
<h1><?php echo $title ?></h1>
<div class="box"> <table border="1" width="90%">
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
<th>简介</th> </tr> <?php
header("content-type:text/html;charset=utf-8");
include_once('mysqlAccount.php');
$conn = mysql_connect(constant("HOST"), constant("userName"), constant("password"));
mysql_query("set names 'utf8'");
mysql_select_db(constant("database_db"));
$tag = true;
$result = mysql_query($sql, $conn);
while ($row = mysql_fetch_array($result)) {
if ($tag) {
echo "<tr><td class='text_color_1'>" . $row["id"] . "</td><td class='text_color_1'>" . $row["name"] . "</td><td class='text_color_1'>" . $row["age"] . "</td><td class='text_color_1'>" . $row["intro"] . "</td></tr>";
$tag = false;
} else {
echo "<tr><td class='text_color'>" . $row["id"] . "</td><td class='text_color'>" . $row["name"] . "</td><td class='text_color'>" . $row["age"] . "</td><td class='text_color'>" . $row["intro"] . "</td></tr>";
$tag = true;
}
}
mysql_free_result($result); ?>
</table>
</div>
<a href="mysqlEdit.php">mysql数据库操作</a>
<a href="index.php" style="float:right;">返回主页</a>
</body>
</html>
<?php
} ?>
createDatabase.php文件:
<?php
header("content-type:text/html;charset=utf-8");
include_once ('mysqlAccount.php');
$conn = mysql_connect(constant("HOST"), constant("userName"), constant("password"));
mysql_query("set names 'utf8'");
$database_db = constant("database_db");
$sql = "create database $database_db"; if (!mysql_query($sql, $conn)) { die('Error: ' . mysql_error());
}
mysql_close($conn);
echo "创建数据库!";
echo "<script>location.href='index.php'</script>"; ?>
createTable.php文件:
<?php
header("content-type:text/html;charset=utf-8");
include_once('mysqlAccount.php');
$conn = mysql_connect(constant("HOST"), constant("userName"), constant("password"));
mysql_query("set names 'utf8'"); mysql_select_db(constant("database_db")); $sql = "create table `pw_luck`(`id` int(10) not null auto_increment primary key,`name` varchar(10) not null,`age` int(10) not null,`intro` varchar(100));"; if (!mysql_query($sql, $conn)) { die('Error: ' . mysql_error());
}
mysql_close($conn);
echo "创建数据表!";
echo "<script>location.href='index.php'</script>"; ?>
dropTable.php文件:
<?php
header("content-type:text/html;charset=utf-8"); include_once ('mysqlAccount.php');
$conn = mysql_connect(constant("HOST"), constant("userName"), constant("password"));
mysql_query("set names 'utf8'"); mysql_select_db(constant("database_db")); $sql = "drop table pw_luck;"; if (!mysql_query($sql, $conn)) { die('Error: ' . mysql_error());
}
mysql_close($conn);
echo "删除数据表!";
echo "<script>location.href='index.php'</script>";
?>
mysqlAccount.php配置文件:
<?php
define("HOST", "localhost");/*mysql数据库连接地址*/
define("userName", "root");/*mysql数据库用户名*/
define("password", "");/*mysql数据库密码*/
define("database_db", "test");/*mysql数据库的数据表名*/ ?>
php安卓服务器软件下载:https://yunpan.cn/cPr8X7jvtkFNN 访问密码 4d7b
安卓版mysql数据库操作案例源码下载:https://yunpan.cn/cPrG5hJuzmYgU 访问密码 a195
安卓版php服务器的mysql数据库增删改查简单案例的更多相关文章
- Java连接MySQL数据库增删改查通用方法
版权声明:本文为博主原创文章,未经博主允许不得转载. Java连接MySQL数据库增删改查通用方法 运行环境:eclipse+MySQL 以前我们Java连接MySQL数据库都是一个数据库写一个类,类 ...
- MySQL数据库(增删改查语句)
MySQL数据库(增删改查语句)一.登录数据库:----> mysql -uroot -proot;(对应用户名和密码)二.SQL语句: 数据定义语言DDL 用来定义数据库.表.列,关 ...
- python操作mysql数据库增删改查的dbutils实例
python操作mysql数据库增删改查的dbutils实例 # 数据库配置文件 # cat gconf.py #encoding=utf-8 import json # json里面的字典不能用单引 ...
- Asp.Net操作MySql数据库增删改查
Asp.Net操作MySql数据库增删改查,话不多说直接步入正题.git源码地址:https://git.oschina.net/gxiaopan/NetMySql.git 1.安装MySQL数据库 ...
- Python实现mysql数据库增删改查
利用python操作mysql数据库用法简单,环境配置容易,本文将实现对库增.删.改.查的简易封装! 1. 环境配置 安装第三方包 ,导入模块 mysql.connector pip inst ...
- 安卓端通过http对Mysql进行增删改查
各类it学习视频,大家都可以看看哦!我自己本人都是通过这些来学习it只知识的! 下面是视频链接转自:http://www.cnblogs.com/yzxk/p/4749440.html Android ...
- jsp-2 简单的servlet连接mysql数据库 增删改查
连接mysql数据库的操作 有增删改查 用的包有 commons-lang3-3.5 mysql-connector-java-5.1.40-bin 但是实际上也就是 数据查询和数据处理两种 所以对数 ...
- python2.7入门---操作mysql数据库增删改查
Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口.Python 数据库接口支持非常多的数据库,你可以选择适合你项目的数据库: G ...
- MySQL数据库增删改查等常用命令介绍
MySQL可以说是最常用的小型数据库,加上现在越来越流行的分布式架构,哪怕是一般的中大型项目也可以用MySQL来进行部署. 数据库的操作最常用的就是增删改查,还有一些切换数据库等操作.以下命令不加说明 ...
随机推荐
- angularJS 系列(五)--controller AS 语法
原文: http://www.cnblogs.com/whitewolf/p/3493362.html 这篇国外的文章也非常好: http://codetunnel.io/angularjs-cont ...
- tcp 的6个控制位
原文:http://blog.chinaunix.net/uid-26413668-id-3376762.html TCP(Transmission Control Protocol) 传输控制协议 ...
- aapt: error while loading shared libraries: libstdc++.so.6: wrong ELF class: ELFCLASS64
前阵子在ubuntu上搭载安卓的开发环境(Eclipse+Sdk+Adt),搭载是完成了,但是却出现了该问题: aapt: error while loading shared libraries: ...
- Shortest Path
Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- JAVA基础-多态
多态 polymophism: 动态绑定, 迟绑定, 指在执行期间(java), 而不是编译期间(javac), 判断所引用对象的实际类型, 根据实际类型调用响应的方法. 3个条件: 1. 继承 2. ...
- php 内置的 webserver 研究。
今天,试了一下通过 php5.4.45 内置的webserver , 在Windows XP 上面能够跑起公司的一个项目,完全无压力.哈哈,只要一个php 就可以,不需要 Apache , Nginx ...
- BNU OJ 51005 BQG's Quadrilateral Bricks
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
- 目前所有的ANN神经网络算法大全
http://blog.sina.com.cn/s/blog_98238f850102w7ik.html 目前所有的ANN神经网络算法大全 (2016-01-20 10:34:17) 转载▼ 标签: ...
- C语言实现GBK/GB2312/五大码之间的转换(转)
源:C语言实现GBK/GB2312/五大码之间的转换 //----------------------------------------------------------------------- ...
- (中等) HDU 1495 非常可乐,BFS。
Description 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享 这一瓶可乐,而且一定要喝的和s ...