I'm coding a setup for my "game" server and I use MySQL for database. I getting an error when I create the database + table and the columns. I tested the Mysql code in phpmyadmin and it worked.
Here's a sample of my code: `
int area;
char user[100];
char pass[100];
char ip[200];
char tentativaspm;
void mysqlsetup(){
MYSQL *CON = mysql_init(NULL);
if (CON == NULL)
{
fprintf(stderr, "%s\n", mysql_error(CON));
exit(1);
}
if (mysql_real_connect(CON, ip, user, pass,
NULL, 0, NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(CON));
mysql_close(CON);
sleep(2);
userepassmysql();
}
printf("Conecao establecida.\n");
if(mysql_query(CON, "CREATE DATABASE place;")){
fprintf(stderr, "%s\n", mysql_error(CON));
mysql_close(CON);
exit(1);
}
if(mysql_query(CON, "USE place; CREATE TABLE grid (pixelID int,color int);"){
fprintf(stderr, "%s\n", mysql_error(CON));
mysql_close(CON);
exit(1);
}
And I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USE
gridCREATE TABLEgrid(pixelIDint(11) NOT NULL,colorint(11) NOT N' at line 1