SA-MP Forums Archive
How to Create the Mysql Table if it doesn`t exist - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to Create the Mysql Table if it doesn`t exist (/showthread.php?tid=476636)



How to Create the Mysql Table if it doesn`t exist? - klaus741258 - 19.11.2013

Hello.
I tried for hours to make this work...
I want to check an the beginning (OnGameModeInit) if the table "accounts" exist or not.
If the table dont exist it should be created.

Код:
	if(mysql_query("SELECT * FROM `accounts`") <= 0)
	{
	
		mysql_query("CREATE TABLE IF NOT EXISTS `accounts` (`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(35), `passwort` varchar(35), `banned` int(1), `admin` int(1), `donater` int(2), `upgradepoints` int(10), `reg` int(1), `sex` int(1), `exp` int(5), `level` int(20), `hand` int(5), `konto` int(30), `crimes` int(3), `arrested` int(1), `wanteddeaths` int(3), `phonebook` int(1), `lottonr` int(3), PRIMARY KEY (`id`));");
		mysql_query("ALTER TABLE `accounts` ADD (`fishes` int(4), `biggestfish` int(5), `job` int(2), `kills` int(10), `deaths` int(10), `jobgehalt` int(10), `headvalue` int(10), `jailed` int(1), `jailtime` int(10), `mats` int(15), `gras` int(15), `kokain` int(15), `helmid` int(6), `kmedizin` int(10), `gmedizin` int(10), `member` int(3), `rank` int(5), `charakter` int(5), `contracttime` int(20), `health` int(5), `interior` int(10));");
		mysql_query("ALTER TABLE `accounts` ADD (`local` int(10), `team` int(10));");
	}
But everytime I start the server I get this message:
Код:
[16:13:52] [MySQL] Error (0): Failed to exeute query. Commands out of sync; you can't run this command now.
[16:13:52] [MySQL] Error (0): Failed to exeute query. Commands out of sync; you can't run this command now.
[16:13:52] [MySQL] Error (0): Failed to exeute query. Commands out of sync; you can't run this command now.
[16:13:52] [MySQL] Error (0): Failed to exeute query. Commands out of sync; you can't run this command now.
[16:13:52] [MySQL] Error (0): Failed to exeute query. Commands out of sync; you can't run this command now.
I get for every query an error, but it creates the table...

And I always got returned 0 if i make this (the table "accounts" exists):
Quote:

mysql_query("SELECT * FROM `accounts`")

So can someone help me and say me, how i could fix this und check if the table exists?

Thanks

Klaus


AW: How to Create the Mysql Table if it doesn`t exist - klaus741258 - 19.11.2013

Nobody knows how I can do this?
Or has anybody only got an idea, that would be very helpfull for me