mysql C编程(一)mysql错误码,关于mysql_errno
假设我们使用mysql_real_query执行了一条sql语句之后,返回值为非0值,大家都知道这是这条语句执行出错,但是我们想
了解地更详细点的话,究竟是什么原因导致了这个错误呢?这时候就得用上mysql提供的另外一个API:mysql_errno。
mysql_errno会提供最近一次调用的C API出错的信息(不见得每个API都会对这个errno进行设置,但是最常用的mysql_real_query是会的)。通过mysql_errno返回的错误码一般都有规则:比如属于区间[1000,2000)的错误是逻辑错误,比如键值冲突这种错误,这些错误是由服务器返回的;其他的比如[2000, 3000)的当然就不是逻辑错误了。
另外,如果想更加详细的信息,可以通过mysql_error函数返回一个错误信息的字符串
相关文档:
1、使用SHOW语句找出在服务器上当前存在什么数据库:
de>de>mysql> SHOW DATABASES; +----------+ | Database | +----------+ | mysql | | test | +----------+ 3 rows in set (0.00 sec)
2、创建一个数据库abccs
mysql> CREATE DATABASE abccs; ......
另外MySql官方出了一个在csharp里面连接MySql的Connector,可以试试
http://dev.mysql.com/downloads/#connector-net
<add name="mysql" connectionString="server=125.46.37.170;uid=root;pwd=;"/>
报错:Unable to connect to any of the specified MySQL hosts.
今天做项目时候就遇到这问 ......
SQLite官方网站例子:
#include <stdio.h>
#include <sqlite3.h>
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
i ......
在网上找到的一个程序
[c]
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
/* 取子串的函数 */
static char* substr(const char*str,unsigned start, unsigned end)
{
unsigned n = end - start;
static char stbuf[256]; ......