mysql 1067 abouting_GitHub - chenxiao07150808/MySQL
MySQL
简单是实现android与php mysql数据库的连接。
这里提供的代码只是为了使你能简单的连接 Android 项目和 PHP,MySQL。你不能把它作为一个标准或者安全编程实践。在生产环境中,理想情况下你需要避免使用任何可能造成潜在注入漏洞的代码(比如 MYSQL 注入)。
涉及的PHP文件
db_connect.php
connect();
}
// destructor
function__destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
functionconnect() {
// import database connection variables
require_once__DIR__ . '/db_config.php';
// Connecting to mysql database
$con= mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) ordie(mysql_error());
// Selecing database
$db= mysql_select_db(DB_DATABASE) ordie(mysql_error()) ordie(mysql_error());
// returing connection cursor
return$con;
}
/**
* Function to close db connection
*/
functionclose() {
// closing db connection
mysql_close();
}
}
?>
怎么调用 :当你想连接 MySQl 数据库或者执行某些操作时,可以这样使用 db_connect.php
$db= newDB_CONNECT(); // creating class object(will open database connection)
create_product.php
对于上面的代码,JSON 的返回值会是:
当 POST 参数丢失
{
"success": 0,
"message": "Required field(s) is missing"
}
当 product 成功创建
{
"success": 1,
"message": "Product successfully created."
}
当插入数据时出现错误
{
"success": 0,
"message": "Oops! An error occurred."
}
get_product_details.php
0) {
$result= mysql_fetch_array($result);
$product= array();
$product["pid"] = $result["pid"];
$product["name"] = $result["name"];
$product["price"] = $result["price"];
$product["description"] = $result["description"];
$product["created_at"] = $result["created_at"];
$product["updated_at"] = $result["updated_at"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echojson_encode($response);
} else{
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echojson_encode($response);
}
} else{
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echojson_encode($response);
}
} else{
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echojson_encode($response);
}
?>
The json response for the above file will be
When successfully getting product details
{
"success": 1,
"product": [
{
"pid": "1",
"name": "iPHone 4S",
"price": "300.00",
"description": "iPhone 4S white",
"created_at": "2012-04-29 01:41:42",
"updated_at": "0000-00-00 00:00:00"
}
]
}
When no product found with matched pid
{
"success": 0,
"message": "No product found"
}
get_all_products.php
0) {
// looping through all results
// products node
$response["products"] = array();
while($row= mysql_fetch_array($result)) {
// temp user array
$product= array();
$product["pid"] = $row["pid"];
$product["name"] = $row["name"];
$product["price"] = $row["price"];
$product["created_at"] = $row["created_at"];
$product["updated_at"] = $row["updated_at"];
// push single product into final response array
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echojson_encode($response);
} else{
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echojson_encode($response);
}
?>
And the JSON response for above code
Listing all Products
{
"products": [
{
"pid": "1",
"name": "iPhone 4S",
"price": "300.00",
"created_at": "2012-04-29 02:04:02",
"updated_at": "0000-00-00 00:00:00"
},
{
"pid": "2",
"name": "Macbook Pro",
"price": "600.00",
"created_at": "2012-04-29 02:04:51",
"updated_at": "0000-00-00 00:00:00"
},
{
"pid": "3",
"name": "Macbook Air",
"price": "800.00",
"created_at": "2012-04-29 02:05:57",
"updated_at": "0000-00-00 00:00:00"
},
{
"pid": "4",
"name": "OS X Lion",
"price": "100.00",
"created_at": "2012-04-29 02:07:14",
"updated_at": "0000-00-00 00:00:00"
}
],
"success": 1
}
When products not found
{
"success": 0,
"message": "No products found"
}
update_product.php
The json reponse of above code, when product is updated successfully
{
"success": 1,
"message": "Product successfully updated."
}
delete_product.php
0) {
// successfully updated
$response["success"] = 1;
$response["message"] = "Product successfully deleted";
// echoing JSON response
echojson_encode($response);
} else{
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echojson_encode($response);
}
} else{
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echojson_encode($response);
}
?>
When product successfully deleted
{
"success": 1,
"message": "Product successfully deleted"
}
When product not found
{
"success": 0,
"message": "No product found"
}
mysql 1067 abouting_GitHub - chenxiao07150808/MySQL相关推荐
- mysql 1067错误,服务无法启动 进程意外终止
无法启动mysql服务,进程意外终止,1067错误 在mysql的主目录下my.ini文件中添加 [WinMySQLServer] server=c:\Program Files\MySQ ...
- Mysql 1067系统错误终极解决方案全集
MySQL手贱把data目录下的系统自带数据库删除了,结果出现了1067系统错误,于是我花了一天时间各种论坛逛,搜集了五种解决1067的方法如下,我属于第一种,后面四种怎么都解决不了 解决方案一 原因 ...
- mysql1067 aborting,Mysql 1067 错误解决方案汇总 | 吴小强的博客
很久没有安装过xampp了,今天从官方网站下载一个最新的回来.启动apache非常成功,当启动mysql的时候提示 1067 错误.以前在winxp下都很正常的,难道在vista下还不一样? 当然首先 ...
- mysql 1067错误原因_关于MySQL的1067错误解决方法
内容: ************* 1 安装MYSQL后更改了ROOT的密码后用 net startmysql 启动时我就遇到了这样的问题.使用以下命令后 c:\mysql\bin\mysqladmi ...
- 安装mysql出现1067_安装MySQL出现1067异常错误
mysql安装1067错误 Microsoft Windows [版本 5.2.3790] (C) 版权所有 1985-2003 Microsoft Corp. C:\Documents and Se ...
- mysql 1067 datadir_MySQL修改datadir后启动服务发生1067错误的解决办法
当前windows下最新版的mysql (5.6.22.0)在安装时没有指定安装路径和数据存放路径的选项,而是默认把程序安装在C盘Program Files下,数据也存放在C:/ProgramData ...
- windows 7下如何卸载重装mysql 压缩包版百度经验_windows下安装、卸载mysql服务的方法(mysql 5.6 zip解压...
MySQL是一个小巧玲珑但功能强大的数据库,目前十分流行.但是官网给出的安装包有两种格式,一个是msi格式,一个是zip格式的.很多人下了zip格式的解压发现没有setup.exe,面对一堆文件一头雾 ...
- c mysql数据库_C实现MySQL数据库操作
C实现MySQL数据库操作 两个月前,也就是9月份,心血来潮在windows下实现了用C连接数据库,当时很是有把linux下一并给实现了.但是没有想得那么简单.这个任务一直推迟到了现在才完成,究其原因 ...
- liunx上mysql源码安装mysql,搞定linux上MySQL编程(一):linux上源码安装MySQL
[版权声明:尊重原创,转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 1. 首先下载源码包: ftp://ftp.jaist.ac.jp/pub/m ...
最新文章
- php如何读写excel
- linux不识别ntfs分区,WinUbuntu下linux无法挂载NTFS格式分区问题的解决
- 写了一个在线流程设计器,效果很炫[Siverlight版本]
- [云炬创业基础笔记]第六章商业模式测试17
- 【超清视频】CCNA系列课程之二:IP地址介绍及VLSM子网划分
- 字幕在看着你:利用恶意字幕文件劫持计算机
- Wireshark 过滤器
- qml鼠标拖动_QML学习笔记(七)— 实现可拖拽、编辑、选中的ListView
- 软件测试过程中主要涉及的文档及其内容
- MATLAB图形用户界面设计(GUI)
- java 验证18位身份证号是否合法
- [转]如何进行人脉管理
- 上古卷轴php代码,【上古卷轴五木柴代码】
- Python基础——PyCharm版本——第八章、文件I/O(核心2——JSON序列化与反序列化——超重点)
- Ceph集群增加Mon时出错:admin_socket: exception getting command descriptions: [Errno 2] No such file or direc
- [内附完整源码和文档] 基于Android的手机音乐播放器的设计与实现
- 酷我音乐盒破解教程(一)
- 这是一款可以批量压缩图片的软件
- mysql数据库显示unknown option '-d' 错误的处理办法
- 利用while 循环判断