HELP! Cannot Creating Table MYSQL
#1

So, I put this code to OnGameModeInit. When I start the server this table is still not created, but other tables can be created. By the way I use MySQL R41
Код:
new query[1024];
format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `business`
  `ID` int(11) NOT NULL default '0',\
  `Name` varchar(%d) default NULL,\
  `Owner` varchar(24) default '-',\
  `BusinessX` float default NULL,\
  `BusinessY` float default NULL,\
  `BusinessZ` float default NULL,\
  `Closed` tinyint(1) default NULL,\
  `Price` int(11) default NULL,\
  `SalePrice` int(11) default NULL,\
  `Earning` int(11) default NULL,", MAX_BUSINESS_NAME);

format(query, sizeof(query), "%s\
  `Money` int(11) default NULL,\
  `Type` int(11) default NULL,\
  `LastVisited` int(11) default NULL,\
  PRIMARY KEY  (`ID`),\
  UNIQUE KEY `ID` (`ID`)\
) ENGINE=InnoDB DEFAULT CHARSET=utf8;", query);

mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `business_perms` (\
  `ID` int(11) NOT NULL auto_increment,\
  `Name` varchar(24) default NULL,\
  `BusinessID` int(11) default NULL,\
  `Can_Deposit` tinyint(1) default NULL,\
  `Can_Take` tinyint(1) default NULL,\
  PRIMARY KEY  (`ID`),\
  KEY `BusinessID` (`BusinessID`),\
  CONSTRAINT `business_perms_ibfk_1` FOREIGN KEY (`BusinessID`) REFERENCES `business` (`ID`) ON DELETE CASCADE\
) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "", "");

mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `business_safelogs` (\
  `ID` int(11) NOT NULL auto_increment,\
  `Name` varchar(24) default NULL,\
  `BusinessID` int(11) default NULL,\
  `Amount` int(11) default NULL,\
  `Date` int(11) default NULL,\
  PRIMARY KEY  (`ID`),\
  KEY `BusinessID` (`BusinessID`),\
  CONSTRAINT `business_safelogs_ibfk_1` FOREIGN KEY (`BusinessID`) REFERENCES `business` (`ID`) ON DELETE CASCADE\
) ENGINE=InnoDB DEFAULT CHARSET=utf8;", "", "");

mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `business_transactions` (\
  `ID` int(11) NOT NULL auto_increment,\
  `OldOwner` varchar(24) default NULL,\
  `NewOwner` varchar(24) default NULL,\
  `Amount` int(11) default NULL,\
  PRIMARY KEY  (`ID`)\
) ENGINE=MyISAM DEFAULT CHARSET=utf8;", "", "");
Reply
#2

Is it only the first one that doesn't get created, or all 4 of them?

If it's only the first, do you actually send the query after formatting to MySQL using this?
Код:
mysql_tquery(g_SQL, query, "", "");
Reply
#3

Try creating them through PHPMyAdmin or perhaps show us your MySQL Log may be there are some errors?
Reply
#4

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Try creating them through PHPMyAdmin or perhaps show us your MySQL Log may be there are some errors?
This is the mysql error logs
Код:
[20:06:03] [ERROR] mysql_tquery: invalid connection handle '0' (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1928 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] mysql_tquery: invalid connection handle '0' (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1939 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] mysql_tquery: invalid connection handle '0' (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1947 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] mysql_tquery: invalid connection handle '0' (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1964 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] mysql_tquery: invalid connection handle '0' (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1965 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] mysql_tquery: invalid connection handle '0' (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1966 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] cache_get_row_count: no active cache (D:\SAMPSERVER\Roleplay\pawno\include\a_mysql.inc:182 -> d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1716 -> d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1968 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [ERROR] cache_get_row_count: no active cache (D:\SAMPSERVER\Roleplay\pawno\include\a_mysql.inc:182 -> d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1362 -> d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1969 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
[20:06:03] [WARNING] mysql_connect: no password specified (d:\SAMPSERVER\Roleplay\gamemodes\Roleplay.pwn:1979 -> D:\SAMPSERVER\Roleplay\pawno\include\YSI\..\YSI_Data\..\YSI_Internal\..\YSI_Core\..\YSI_Internal\..\YSI_Server\y_scriptinit.inc:236)
Reply
#5

As you can see in your logs, MYSQL connection is not successful. Show me your SQL defines and mysql_connect line.
Reply
#6

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Is it only the first one that doesn't get created, or all 4 of them?

If it's only the first, do you actually send the query after formatting to MySQL using this?
Код:
mysql_tquery(g_SQL, query, "", "");
All of them
Reply
#7

Quote:
Originally Posted by GTLS
Посмотреть сообщение
As you can see in your logs, MYSQL connection is not successful. Show me your SQL defines and mysql_connect line.
I put this code after the mysql code above
Код:
//=============================//
new MySQLOpt: option_id = mysql_init_options();
mysql_set_option(option_id, AUTO_RECONNECT, true);
g_SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, option_id);
if (g_SQL == MYSQL_INVALID_HANDLE || mysql_errno(g_SQL) != 0)
{
	print("MySQL connection failed. Server is shutting down.");
	print("[House System] Can't connect to MySQL.");
	print("  [Business System] Can't connect to MySQL. (Error #%d)");
	SendRconCommand("exit");
	return 1;
}
print("MySQL connection is successful.");
print("[HOUSE]MySQL connection is successful.");
print("[BUSINESS]MySQL connection is successful.");
print("\nThis Roleplay Gamemode is made by");
print("====MaulaSufa====");
print("Welcome to MSRP");
print("\n");
Reply
#8

This is the SQL define code
Код:
#define		MYSQL_HOST 		"localhost"
#define		MYSQL_USER 		"root"
#define		MYSQL_PASSWORD 		""
#define		MYSQL_DATABASE 		"roleplay database"
Reply
#9

OH MY GOD XD Finally i solved the problem. I just need to put mysql_connect code above mysql_tquery in GameModeInit xD. so this problem is SOLVED
Reply
#10

Offcourse you have to Connect first then you can do stuff inside.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)