Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: ! on Apr 03, 2017, 11:51 AM

Title: [MYSQL]Query returns false!
Post by: ! on Apr 03, 2017, 11:51 AM
Created Table using
MYSQLTest <- mysql_connect("blabla", "blabla", "blabla", "blabla");
mysql_query( MYSQLTest, "CREATE TABLE IF NOT EXISTS TTP( Name TEXT, TTP NUMERIC, Onine_Time TEXT )" );
Now by simply using this query
local myqueryttp = mysql_query( MYSQLTest,"SELECT Name FROM TTP WHERE Name='"+player.Name+"'");
The query returns false & connection and everything else is fine. :(
Title: Re: [MYSQL]Query returns false!
Post by: Shadow on Apr 03, 2017, 12:30 PM
Not trying to be rude but, why would you query for a name if you know the name? lol
Title: Re: [MYSQL]Query returns false!
Post by: vito on Apr 03, 2017, 12:57 PM
Quote from: Shadow on Apr 03, 2017, 12:30 PMNot trying to be rude but, why would you query for a name if you know the name? lol
To check if name exists in "TTP" maybe.
Title: Re: [MYSQL]Query returns false!
Post by: ! on Apr 03, 2017, 03:30 PM
Quote from: vito on Apr 03, 2017, 12:57 PM
Quote from: Shadow on Apr 03, 2017, 12:30 PMNot trying to be rude but, why would you query for a name if you know the name? lol
To check if name exists in "TTP" maybe.
Yup
its just an example of simple query which returns false everytime.
Any idea how to fix this.
Title: Re: [MYSQL]Query returns false!
Post by: Thijn on Apr 03, 2017, 04:29 PM
What does mysql_error return?
Title: Re: [MYSQL]Query returns false!
Post by: . on Apr 03, 2017, 05:00 PM
To that query, I would suggest limiting the results to 1 (https://www.w3schools.com/php/php_mysql_select_limit.asp) in order to prevent searching the remaining rows if the condition was met. Thus avoiding the removal of hot data from the cache to make room for something that isn't even relevant.
Title: Re: [MYSQL]Query returns false!
Post by: vito on Apr 03, 2017, 05:04 PM
Maybe there should be used COUNT() because one don't need a data from table, just checking.
Title: Re: [MYSQL]Query returns false!
Post by: . on Apr 03, 2017, 05:11 PM
COUNT() is kinda irrelevant since you only select a single row. This is equal to simply selecting the row ID instead of the name. Except the latter might be simpler and or faster.
Title: Re: [MYSQL]Query returns false!
Post by: vito on Apr 03, 2017, 05:38 PM
Dunno, need to make a benchmark w/o cache to test what is faster.
Title: Re: [MYSQL]Query returns false!
Post by: ! on Apr 03, 2017, 06:37 PM
Quote from: Thijn on Apr 03, 2017, 04:29 PMWhat does mysql_error return?
Not tried ill check..

Quote from: happymint on Apr 03, 2017, 05:00 PMTo that query, I would suggest limiting the results to 1 (https://www.w3schools.com/php/php_mysql_select_limit.asp) in order to prevent searching the remaining rows if the condition was met. Thus avoiding the removal of hot data from the cache to make room for something that isn't even relevant.
I cant, actually i am using queries for webstats.
The given example was just to show that simple query returns false.

Quote from: vito on Apr 03, 2017, 05:38 PMDunno, need to make a benchmark w/o cache to test what is faster.
Ill try it tomorrow.
Title: Re: [MYSQL]Query returns false!
Post by: Cool on Apr 08, 2017, 07:24 AM
@zeus Give proper permissions to your db or check table is exists or not because i run the same query only change the db name and tabble name its not giving any error
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi65.tinypic.com%2F2im9s05.png&hash=1c150e3f61efc3d2cc8fd6b9bad277cd70aa1347)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi66.tinypic.com%2Feameit.png&hash=2cdad8e22abc7c48774826679eeef45700520acc)