Last active
September 16, 2016 09:50
-
-
Save bitsmanent/09e4ed2864b02f79e5af80b52e925f6e to your computer and use it in GitHub Desktop.
Run a parametrized MySQL query (printf()-like).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MYSQL_RES * | |
| mysql_exec(const char *sqlstr, ...) { | |
| MYSQL_RES *res; | |
| va_list ap; | |
| char *sql; | |
| int sqlen; | |
| va_start(ap, sqlstr); | |
| sqlen = vasprintf(&sql, sqlstr, ap); | |
| va_end(ap); | |
| if(mysql_real_query(mysql, sql, sqlen)) { | |
| free(sql); | |
| return NULL; | |
| } | |
| free(sql); | |
| res = mysql_store_result(mysql); | |
| if(!res) | |
| return NULL; | |
| return res; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment