Skip to main content
  1. Posts/

linux 下C++ 连接mysql 数据库

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

资料推荐这个:MySQL C API programming tutorial

环境为ubuntu 14.04 lts

需要安装mysql 和mysql 开发包

sudo apt-get install libmysqlclient15-dev  mysql-server mysql-client

先在mysql  中建立test数据库和test表格

 mysql>create database test; 

    mysql>use test;    //切换到test数据库中

    mysql> create table test(name varchar(255),num int(10) ); //创建一个叫test的表

    mysql>show create table test;  //显示刚才创建的表信息

    mysql> select * from test;   //查询test表中数据

    mysql>quit

然后用如下cpp代码连接

 1#include <cstdio>
 2#include <mysql.h>
 3#include <cstring>
 4int main(int argc,char *argv[])
 5{
 6	MYSQL conn;
 7	int res;
 8	mysql_init(&conn);
 9	if (mysql_real_connect(&conn,"localhost","root","2254965","test",0,NULL,CLIENT_FOUND_ROWS))
10	{
11		puts("connect success");
12		res = mysql_query(&conn,"insert into test values('sensetime','23333')");
13		if (res) puts("error");
14		else puts("success");
15		printf("res=%d\n",res);
16	}
17
18	return 0;
19}

编译:

g++ test.cpp `mysql_config --cflags --libs` -o test

此次从mysql中查询,发现成功插入了一条数据.

Related

geekos project 1 (ELF文件相关)

·3 mins
一、目的 熟悉ELF文件格式,了解GeekOS系统如何将ELF格式的可执行程序装入到内存,建立内核进程并运行的实现技术。 二、流程 1、修改/geekos/elf.c文件:在函数Parse_ELF_Executable( )中添加代码,分析ELF格式的可执行文件(包括分析得出ELF文件头、程序头,获取可执行文件长度,代码段、数据段等信息),并填充Exe_Format数据结构中的域值。 2、在Linux环境下编译系统得到GeekOS镜像文件。 3、编写一个相应的bochs配置文件。 4、在bochs中运行GeekOS系统显示结果。

atom在linux下安装插件失败的解决方案

·1 min
1gyp info it worked if it ends with ok 2gyp info using node-gyp@2.0.2 3gyp info using node@0.10.40 | linux | x64 4gyp http GET https://atom.io/download/atom-shell/v0.34.0/node-v0.34.0.tar.gz 5gyp WARN install got an error, rolling back install 6gyp ERR! install error 7gyp ERR! stack Error: This is most likely not a problem with node-gyp or the package itself and 8gyp ERR! stack is related to network connectivity. In most cases you are behind a proxy or have bad 9gyp ERR! stack network settings. 10gyp ERR! stack at Request.<anonymous> (/opt/atom/resources/app/apm/node_modules/npm/node_modules/node-gyp/lib/install.js:234:21) 11gyp ERR! stack at Request.emit (events.js:95:17) 12gyp ERR! stack at Request.onRequestError (/opt/atom/resources/app/apm/node_modules/npm/node_modules/request/request.js:861:8) 13gyp ERR! stack at ClientRequest.emit (events.js:95:17) 14gyp ERR! stack at Socket.socketErrorListener (http.js:1548:9) 15gyp ERR! stack at Socket.emit (events.js:95:17) 16gyp ERR! stack at net.js:834:16 17gyp ERR! stack at process._tickCallback (node.js:448:13) 18gyp ERR! System Linux 3.16.0-38-generic 19gyp ERR! command "/opt/atom/resources/app/apm/bin/node" "/opt/atom/resources/app/apm/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "install" "--target=0.34.0" "--dist-url=https://atom.io/download/atom-shell" "--arch=x64" "--ensure" 20gyp ERR! cwd /home/rkz2013/.atom 21gyp ERR! node -v v0.10.40 22gyp ERR! node-gyp -v v2.0.2 23gyp ERR! not ok 解决办法是不用apm install 而是用npm install…之前要安装一个npm