How to check if script succesfully connected to the mysql ?
#1

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);
Reply
#2

Код:
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
Reply
#3

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
Reply
#4

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.
Reply
#5

Thx, Fuck i can't give you other +rep bec i already did yesterday when you helped me lol
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)