How to check if script succesfully connected to the mysql ? - 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 check if script succesfully connected to the mysql ? (
/showthread.php?tid=625788)
How to check if script succesfully connected to the mysql ? -
fastayko - 06.01.2017
how to check if the script succesfully connected to the DB or no and store the returned value in the same time?
new MySQL:g_Sql;
g_Sql = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
Re: How to check if script connected to the mysql ? -
GoldenLion - 06.01.2017
Код:
mysqL_errno(MySQL:handle = MYSQL_DEFAULT_HANDLE)
it will return 0 if there were no problems performing the MySQL operation, otherwise it will return the error code.
This is how you can use it after mysql_connect:
Код:
if (mysql_errno()) print("Failed to connect to the database."); // 0 - no errors
else print("Successfully connected to the database."); // there's an error
Re: How to check if script succesfully connected to the mysql ? -
fastayko - 06.01.2017
i didn't undrestand how to use it can you give me a an example to check if the script succesfully connected to the DB or no and store the returned value in the same time
Re: How to check if script succesfully connected to the mysql ? -
GoldenLion - 06.01.2017
Quote:
Originally Posted by fastayko
i didn't undrestand how to use it can you give me a an example to check if the script succesfully connected to the DB or no and store the returned value in the same time
|
I gave you an example above.
Код:
new MySQL:g_Sql, error; //somewhere on top of your script
//somewhere under ongamemodeinit or something
g_Sql = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
error = mysql_errno();
if (error) print("Failed to connect to the database.");
else print("Successfully connected to the database.");
Next time go here:
https://sampwiki.blast.hk/wiki/MySQL/R40. It has all functions with examples.
Re: How to check if script succesfully connected to the mysql ? -
fastayko - 06.01.2017
Thx, Fuck i can't give you other +rep bec i already did yesterday when you helped me lol