3 const char *db,
unsigned int port,
const char *socket,
bool connectNow)
8 sql = mysql_init(NULL);
10 mysql_options(sql, MYSQL_OPT_RECONNECT, (
const char*)&reconnect);
11 if (mysql_real_connect(sql, host, user, passwd, db, port, socket, 0))
14 mysql_options(sql, MYSQL_OPT_RECONNECT, (
const char*)&reconnect);
21 if(host)this->host = strdup(host);
22 if(user)this->user = strdup(user);
23 if(passwd)this->passwd = strdup(passwd);
24 if(db)this->db = strdup(db);
26 if(socket)this->socket = strdup(socket);
27 else this->socket = NULL;
32 if(sql)mysql_close(sql);
35 if(passwd)
free(passwd);
37 if(socket)
free(socket);
45 mysql_options(sql, MYSQL_OPT_READ_TIMEOUT, (
const char*)&readTimeout);
46 mysql_options(sql, MYSQL_OPT_WRITE_TIMEOUT, (
const char*)&writeTimeout);
52 return sql != NULL ? (mysql_ping(sql) == 0) :
false;
66 if(sql)mysql_close(sql);
67 sql = mysql_init(NULL);
68 if (mysql_real_connect(sql, host, user, passwd, db, port, socket, 0))
72 mysql_options(sql, MYSQL_OPT_RECONNECT, (
const char*)&reconnect);
83 if(sql && mysql_set_character_set(sql, character) == 0)
94 if (!sql || (data = (
char *) malloc(size)) == NULL)
100 va_start(ap, pattern);
101 n = vsnprintf(data, size, pattern, ap);
103 if (n > -1 && n < size)
111 if ((data = (
char *) realloc(data, size)) == NULL)
116 if (mysql_query(sql, data) == 0)
130 return mysql_store_result(sql);
135 return mysql_use_result(sql);
140 return mysql_fetch_row(res);
150 return mysql_insert_id(sql);
155 return mysql_error(sql);
160 return mysql_error(this->sql);
165 return mysql_errno(this->sql);
173 unsigned long len = strlen(str);
174 if( (result = (
char *) malloc((len << 1) + 1)) == NULL )
178 len = mysql_real_escape_string(this->sql, result, str, len);
180 result = (
char *) realloc(result, len + 1);
187 return mysql_affected_rows(this->sql);
192 return mysql_num_rows(res);
198 stmt = mysql_stmt_init(sql->sql);
201 if(!mysql_stmt_prepare(stmt, query, strlen(query)))
203 paramCount= mysql_stmt_param_count(stmt);
206 bindParam =
new MYSQL_BIND[paramCount];
207 bzero(bindParam,
sizeof(MYSQL_BIND) * paramCount);
215 if(bindParam)
delete []bindParam;
216 mysql_stmt_close(stmt);
221 return mysql_stmt_execute(stmt)==0;
226 if(index < paramCount)
228 return &(bindParam[
index]);
235 return mysql_stmt_bind_param(stmt, bindParam) == 0;
240 return mysql_stmt_error(stmt);