MySQL crashes the server

Started by KAKAN, Jan 02, 2016, 11:13 AM

Previous topic - Next topic

KAKAN

Hello all. Hope all are fine.
Today, I was trying something like this:-
function onScriptLoad(){
db <- mysql_connect(...); //... is filled with connection info
db2 <- ConnectSQL("db.db");
print( mysql_ping( db ) );
print( mysql_ping( db2 ) );
}
When the 2nd print statement( ping db2 ) executes, the server crashes. This shouldn't happen I guess.

2nd code:
local q = mysql_query(db,"SELECT * FROM Accounts WHERE Name='KAKAN'");
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_length( q ) );
mysql_free_result( q );
It too crashed my server dunno why.
Can anybody tell me the reason why does it crash my server?
oh no

Thijn

1st. A bug. Thanks.
2nd. It's mysql_fetch_lengths
Although I'm unsure why it would crash...
Try putting an if (q) around it. Maybe the query failed and freeing it crashed.

DizzasTeR

#2
How is this string going to work in the first place?
"SELECT * FROM Accounts WHERE Name='KAKAN'"
Edit: I went to test it, it actually worked, my bad :D

Drake

Quote from: KAKAN on Jan 02, 2016, 11:13 AMfunction onScriptLoad(){
db <- mysql_connect(...); //... is filled with connection info
db2 <- ConnectSQL("db.db");
print( mysql_ping( db ) );
[b]print( mysql_ping( db2 ) );[/b]
}
When the 2nd print statement( ping db2 ) executes, the server crashes. This shouldn't happen I guess.

Are you really trying to ping a SQLite db with a MySQL function?
It's obvious that it will crash as "db2" isn't a MySQL DB.

KAKAN

Quote from: Drake on Jan 02, 2016, 12:04 PM
Quote from: KAKAN on Jan 02, 2016, 11:13 AMfunction onScriptLoad(){
db <- mysql_connect(...); //... is filled with connection info
db2 <- ConnectSQL("db.db");
print( mysql_ping( db ) );
[b]print( mysql_ping( db2 ) );[/b]
}
When the 2nd print statement( ping db2 ) executes, the server crashes. This shouldn't happen I guess.

Are you really trying to ping a SQLite db with a MySQL function?
It's obvious that it will crash as "db2" isn't a MySQL DB.
It can return false or null on that, why would it crash?

Quote from: Thijn on Jan 02, 2016, 11:44 AM1st. A bug. Thanks.
2nd. It's mysql_fetch_lengths
Although I'm unsure why it would crash...
Try putting an if (q) around it. Maybe the query failed and freeing it crashed.
Well the query is working. I have tried it, it crashes somehow.
oh no

Drake

Quote from: KAKAN on Jan 02, 2016, 12:09 PM
Quote from: Drake on Jan 02, 2016, 12:04 PM
Quote from: KAKAN on Jan 02, 2016, 11:13 AMfunction onScriptLoad(){
db <- mysql_connect(...); //... is filled with connection info
db2 <- ConnectSQL("db.db");
print( mysql_ping( db ) );
[b]print( mysql_ping( db2 ) );[/b]
}
When the 2nd print statement( ping db2 ) executes, the server crashes. This shouldn't happen I guess.

Are you really trying to ping a SQLite db with a MySQL function?
It's obvious that it will crash as "db2" isn't a MySQL DB.
It can return false or null on that, why would it crash?
Why would you even try to use MySQL function for a SQLite DB?
What makes you think that "mysql_ping" will return 'null'?  and the simple answer about the "mysql_ping" is that, it either returns true or false when the db is actually connected. If your MySQL DB isn't connected or gets disconnected for some reason and you'll try to ping it, it'll still crash the server.

KAKAN

Quote from: Drake on Jan 02, 2016, 12:16 PM
Quote from: KAKAN on Jan 02, 2016, 12:09 PM
Quote from: Drake on Jan 02, 2016, 12:04 PM
Quote from: KAKAN on Jan 02, 2016, 11:13 AMfunction onScriptLoad(){
db <- mysql_connect(...); //... is filled with connection info
db2 <- ConnectSQL("db.db");
print( mysql_ping( db ) );
[b]print( mysql_ping( db2 ) );[/b]
}
When the 2nd print statement( ping db2 ) executes, the server crashes. This shouldn't happen I guess.

Are you really trying to ping a SQLite db with a MySQL function?
It's obvious that it will crash as "db2" isn't a MySQL DB.
It can return false or null on that, why would it crash?
Why would you even try to use MySQL function for a SQLite DB?
What makes you think that "mysql_ping" will return 'null'?  and the simple answer about the "mysql_ping" is that, it either returns true or false when the db is actually connected. If your MySQL DB isn't connected or gets disconnected for some reason and you'll try to ping it, it'll still crash the server.
What if I actually put the connection within a try catch block and the mysql connection is wrong. THen if I use mysql_ping, it would crash.
For ex:-
try{
db <- mysql_connect(..."Wrong one"); //Wrong connection
}catch(e){}
mysql_ping(db);
It would still crash the server if the mysql connection is unsuccessful.
My main problem is with that.
it crashes the server, if we can find a way to make it return null, then it won't crash my server when I would be afk.
oh no

.

function onScriptLoad(){
db2 <- ConnectSQL("db.db");
print( mysql_ping( db2 ) );
}

What dafuq is this? You're trying to use a MySQL function on a SQLite database? Of course it will crash.

local q = mysql_query(db,"SELECT * FROM Accounts WHERE Name='KAKAN'");
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_length( q ) );
mysql_free_result( q );

You never check for null values. As far as I know, "mysql_query" could've returned null and therefore "q" is null. You wouldn't know that because the MySQL plugin doesn't throw any errors. It just silently tries to screw you. And you're trying to use the returned value without checking for validity.

local q = mysql_query(db,"SELECT * FROM Accounts WHERE Name='KAKAN'");
if (!q) throw "bad mysql result fool!";
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_length( q ) );
mysql_free_result( q );
.

KAKAN

Quote from: S.L.C on Jan 02, 2016, 12:35 PMfunction onScriptLoad(){
db2 <- ConnectSQL("db.db");
print( mysql_ping( db2 ) );
}

What dafuq is this? You're trying to use a MySQL function on a SQLite database? Of course it will crash.

local q = mysql_query(db,"SELECT * FROM Accounts WHERE Name='KAKAN'");
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_length( q ) );
mysql_free_result( q );

You never check for null values. As far as I know, "mysql_query" could've returned null and therefore "q" is null. You wouldn't know that because the MySQL plugin doesn't throw any errors. It just silently tries to screw you. And you're trying to use the returned value without checking for validity.

local q = mysql_query(db,"SELECT * FROM Accounts WHERE Name='KAKAN'");
if (!q) throw "bad mysql result fool!";
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_length( q ) );
mysql_free_result( q );
Replacing;-
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_length( q ) );to:-
if( mysql_num_rows( q ) != 0 ) print( mysql_fetch_lengths( q ) );Because the function is mysql_fetch_lengths.
ontopic:- The server still crashes
oh no

Drake

Quote from: KAKAN on Jan 02, 2016, 12:49 PMontopic:- The server still crashes
Can't help it after you have been told the solution twice.

KAKAN

Quote from: Drake on Jan 02, 2016, 01:07 PM
Quote from: KAKAN on Jan 02, 2016, 12:49 PMontopic:- The server still crashes
Can't help it after you have been told the solution twice.
Not talking about mysql_ping....
If you guys don't believe me, try it yourself then blame me.
oh no