VC用MYSQL提供的LIB查询数据库
#include "winsock.h"
#include "mysql.h"
void query_example(void)
{
MYSQL *pDbCon = NULL;
char *pszHost = "localhost";
char *pszUser = "guest";
char *pszPsw = "";
char *pszDbName = "mysql_db_name";
int iPort = 3306;
pDbCon = mysql_init((MYSQL*) 0);
if (NULL != pDbCon)
{
if (mysql_real_connect(pDbCon, pszHost, pszUser, pszPsw, pszDbName, iPort, NULL, 0))
{
if (!mysql_select_db(pDbCon, pszDbName))
{
pDbCon->reconnect = 1;
char *pszSql = "select * from tb_name";
if (!mysql_query(pDbCon, pszSql))
{
long i = 0;
MYSQL_RES *pReSet = mysql_store_result(pDbCon);
long iFieldNum = mysql_num_fields(pReSet);
long iRecordNum = (long)mysql_num_rows(pReSet);
//printf name of fields
MYSQL_FIELD *pField = mysql_fetch_fields(pReSet);
for (i = 0; i < iFieldNum; i++)
{
//printf("%s, ", pField[i].name);
}
//printf all data
MYSQL_ROW stRow;
while (stRow = mysql_fetch_row(pReSet))
{
//printf row's data
for (i = 0; i < iFieldNum; i++)
{
if (stRow[i] != NULL)
{
//printf("%s ", stRow[i]);
}
}
}
}
}
else
{
//printf("unable to select the database!\n");
}
}
else
{
//printf("can't connect to the mysql server!\n");
}
mysql_close(pDbCon);
}
}
相关文档:
mysql> explain select count(id) from t_prehandle_zhigao_05 as zhigao where start_time > '2008-05-30';
+----+-------------+--------+-------+---------------+------------+---------+------+---------+--------------------------+
| id | select_type | table | type | p ......
Linux下进行MYSQL的C++编程起步手记
首先安装必需的开发包
sudo apt-get install gcc g++ libgcc1 libg++ make gdb
安装MYSQL的C语言开发包
sudo apt-get install libmysql++-dev libmysql++2c2a libmysqlclient15-dev libmysqlclient15off
......
如若转载本文,请注明原始出处:http://hi.baidu.com/hexiong/blog/item/e860e5dd9b0d3ae376c6381a.html
(hexiong@baidu or iihero@CSDN)
偶尔碰到有人问使用mysql命令行,老让人输入--default-character-set=gbk之类无聊的选项,让人烦。让人多输入了几个字符,确实有点不对劲。
加上有时候自己有时候DIY,很少在window ......
mysql
命令集锦
测试环境:mysql 5.0.45
【注:可以在mysql
中通过mysql>
SELECT VERSION();
来查看数据库版本】
一、连接MYSQL
。
格式: mysql -h
主机地址 -u
用户名
-p
用户密码
1
、连接到本机上的MYSQL
。
首先打开DOS
窗口,然后进入目录mysql\bin
,再键入命令mysql -u r ......