linux下apache表单与mysql的连接
2013-10-22 08:22
246 查看
之前写了linux下apache表单与c语言写的cgi程序和c语言与mysql的连接,今天这里就写下apache表单与mysql的连接:
1、创建一新空表
CREATE TABLE num(
ID int(11) NOT NULL auto_increment,
first int(11),
second int(11),
PRIMARY KEY (ID)
);
程序如下:
执行程序,其他步骤如上篇文章,结果如下:
1、创建一新空表
CREATE TABLE num(
ID int(11) NOT NULL auto_increment,
first int(11),
second int(11),
PRIMARY KEY (ID)
);
程序如下:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "mysql.h" #define SELECT_QUERY "insert into webnum(first,second) values(%d,%d)" int main(void) { MYSQL con,*sock; MYSQL_RES *res; MYSQL_ROW row; char qbuf[160]; char *data,*p; int i=1; char tem[4][50]; /*与表单联系*/ printf("content-type:text/html;charset=gb2312\n\n"); data=getenv("QUERY_STRING"); printf("data=%s<br>\n",data); p = strtok(data,"=&"); strcpy(tem[0],p); while((p = strtok(NULL,"=&"))){ strcpy(tem[i],p); i++; } printf("the frist word is %s<br>",tem[1]); printf("the second word is %s<br>",tem[3]); /*与mysql连接*/ mysql_init(&con); if(sock=(mysql_real_connect(&con,"localhost","root","wangsong110","foo",0,NULL,0))){ printf("Connection success\n"); } sprintf(qbuf,SELECT_QUERY,atoi(tem[1]),atoi(tem[3])); mysql_query(sock,qbuf); mysql_close(sock); return 0; }
执行程序,其他步骤如上篇文章,结果如下:
相关文章推荐
- apache mod_xsendfile 让php提供更快的文件下载
- apache mod_xsendfile 让php提供更快的文件下载
- 编译安装apache-2.4.6
- linux下安装apache步骤
- linux下简单的apache表单+c语言写cgi程序
- apache安装过程中的常见问题
- apache安装过程中的常见问题
- Apache的FileUpload用于Servlet与JSP环境下的文件上传
- CentOS6 配置svn+apache使用linux本地账户认证
- android真机 调用笔记本Apache
- mac 系统下的Apache + PHP
- apache基本配置
- default charset for apache
- 让Apache不显示版本号
- Htaccess文件用法集锦
- apache配置优化(七)
- apache配置优化(六)
- Apache虚拟主机的配置
- Building Apache2 From Source on Linux (Redhat 8)
- redhat/ubuntu 配置apache, mysql自启动