|
Why would you need to do so in the first place? Why do you decide to execute them via a file rather than the script itself, as it'd just make it less efficient from having to parse the data from the file. The only advantage I can see is not having to re-compile the script every time you want to add a new line, but that takes mere seconds.
Either way, what errors are you receiving? |
CREATE TABLE IF NOT EXISTS `Accounts` ( `Username` varchar(25) NOT NULL, `Password` varchar(129) NOT NULL, `aLevel` int(11) NOT NULL, `aPassword` varchar(129) NOT NULL, `Money` int(11) NOT NULL, `Score` int(11) NOT NULL, UNIQUE KEY `Username` (`Username`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `Ban Logs` ( `Log ID` int(11) NOT NULL auto_increment, `Administrator` varchar(25) NOT NULL, `Player` varchar(25) NOT NULL, `Reason` varchar(150) NOT NULL, `Length` varchar(128) NOT NULL, PRIMARY KEY (`Log ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; CREATE TABLE IF NOT EXISTS `CMD Logs` ( `Log ID` int(11) NOT NULL auto_increment, `Player` varchar(25) NOT NULL, `cmdtext` varchar(300) NOT NULL, PRIMARY KEY (`Log ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; CREATE TABLE IF NOT EXISTS `Kick Logs` ( `Log ID` int(11) NOT NULL auto_increment, `Administrator` varchar(25) NOT NULL, `Player` varchar(25) NOT NULL, `Reason` varchar(150) NOT NULL, PRIMARY KEY (`Log ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
[17:17:33] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS `Accounts` ( ) - An error has occured. (Error ID: 1064, 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 '' at line 1) [17:17:33] OnQueryError() - Called.
|
There's nothing wrong with the SQL syntax inside the file, so something is screwing up when loading the data or calling it to the query. Please show that code.
|
stock CreateSQLTables()
{
new szQuery[2000];
new File:sqltables = fopen("sql.txt", io_read);
fread(sqltables, szQuery);
fclose(sqltables);
mysql_query(szQuery);
}
stock CreateSQLTables( )
{
new szQuery[ 2000 ];
new szLine[ 128 ];
new File: sqltables = fopen( "sql.txt", io_read );
while( fread( sqltables, szLine ) )
{
strcat( szQuery, szLine );
// You may need to add \n to the end of the line due to syntax
}
fclose( sqltables );
mysql_query( szQuery );
}
|
fread only reads one line of the file at a time. You'll need to read the whole file, then execute the query.
pawn Код:
|
mysql_query( "CREATE TABLE IF NOT EXISTS ..." );
// Cram them all into one query, or separate them by tables
I'll do it that way instead, it's more efficient anyways. Plus, with threaded queries it won't cause any lag!stock CreateSQLTables()
{
mysql_query("CREATE TABLE IF NOT EXISTS `Accounts` ( \
`Username` varchar(25) NOT NULL, \
`Password` varchar(129) NOT NULL, \
`aLevel` int(11) NOT NULL, \
`aPassword` varchar(129) NOT NULL, \
`Money` int(11) NOT NULL, \
`Score` int(11) NOT NULL, \
UNIQUE KEY `Username` (`Username`) \
) ENGINE=MyISAM DEFAULT CHARSET=latin1;", qNormal);
mysql_query("CREATE TABLE IF NOT EXISTS `Ban Logs` ( \
`Log ID` int(11) NOT NULL auto_increment, \
`Administrator` varchar(25) NOT NULL, \
`Player` varchar(25) NOT NULL, \
`Reason` varchar(150) NOT NULL, \
`Length` varchar(128) NOT NULL, \
PRIMARY KEY (`Log ID`) \
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;", qNormal);
mysql_query("CREATE TABLE IF NOT EXISTS `CMD Logs` ( \
`Log ID` int(11) NOT NULL auto_increment, \
`Player` varchar(25) NOT NULL, \
`cmdtext` varchar(300) NOT NULL, \
PRIMARY KEY (`Log ID`) \
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;", qNormal);
mysql_query("CREATE TABLE IF NOT EXISTS `Kick Logs` ( \
`Log ID` int(11) NOT NULL auto_increment, \
`Administrator` varchar(25) NOT NULL, \
`Player` varchar(25) NOT NULL, \
`Reason` varchar(150) NOT NULL, \
PRIMARY KEY (`Log ID`) \
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;", qNormal);
}