1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-09 01:07:16 +01:00
SqMod/module/Vendor/MDBC/examples/mysql_debug.c
2020-03-22 14:54:40 +02:00

41 lines
947 B
C

#include <mysql.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void show_error(MYSQL *mysql)
{
printf("Error(%d) [%s] \"%s\"", mysql_errno(mysql),
mysql_sqlstate(mysql),
mysql_error(mysql));
mysql_close(mysql);
exit(-1);
}
int main(int argc, char *argv[])
{
MYSQL *mysql;
const char *query;
mysql_debug("d:t:O");
mysql= mysql_init(NULL);
if (!mysql_real_connect(mysql, "localhost", "example", "example_pw",
"example_db", 0, "/tmp/mysql.sock", 0))
show_error(mysql);
query= "DROP TABLE IF EXISTS debug_example";
if (mysql_real_query(mysql, query, strlen(query)))
show_error(mysql);
query= "CREATE TABLE debug_example (id int not null, my_name varchar(50),"
"PRIMARY KEY(id))";
if (mysql_real_query(mysql, query, strlen(query)))
show_error(mysql);
mysql_close(mysql);
return 0;
}