SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/09/2012, 12:14 PM   #1
Ronaldo_raul™
Gangsta
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: .
Posts: 999
Reputation: 67
Default Mysql Experts, take a look please.

Hello, I've been scripting in MySQL since 3 days. I've learnt the basic things, but now I want to expertise my MySQL coding skills. Since, MySQL is a great saving system, I am finding ways to expertise it. What I want to know is what silly mistakes people makes that aren't to be made. So, basically can anyone give me a guide through how can I optimise my MySQL codes. How to and where to properly use some functions like -
pawn Code:
mysql_free_results () ;

and another things like -
should we really do things like this -
pawn Code:
mysql_query ( "UPDATE `user` SET a=1 , b=2 WHERE `Name` = '%s'" ) ;

OR

pawn Code:
mysql_query ( "UPDATE user SET a=1 , b=2 WHERE Name = '%s'" ) ;


Where to use [``] and where not to ?
Maybe a deep knowledge and guide can help me.

Thank you.

Obediently,
Ronaldo_raul
Ronaldo_raul™ is offline   Reply With Quote
Old 16/09/2012, 12:19 PM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,086
Reputation: 2655
Default Re: Mysql Experts, take a look please.

1. You only need to free a result if you have stored one in the first place (mysql_store_result), so usually only after SELECT queries.

2. You only need to use backticks if the table or column name is a MySQL keyword.
__________________
Vince is offline   Reply With Quote
Old 16/09/2012, 12:34 PM   #3
Ronaldo_raul™
Gangsta
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: .
Posts: 999
Reputation: 67
Default Re: Mysql Experts, take a look please.

Quote:
Originally Posted by Vince View Post
1. You only need to free a result if you have stored one in the first place (mysql_store_result), so usually only after SELECT queries.

2. You only need to use backticks if the table or column name is a MySQL keyword.
Thank you.

erm, about the second answer. Keyword ? I don't get it. Can you give me some precise examples ?

Thank you once again for the quick reply.

I am being so impatient to know more about optimizations. Can you point out some tricks ?
Ronaldo_raul™ is offline   Reply With Quote
Old 16/09/2012, 12:47 PM   #4
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,086
Reputation: 2655
Default Re: Mysql Experts, take a look please.

http://dev.mysql.com/doc/refman/5.0/...ved-words.html
__________________
Vince is offline   Reply With Quote
Old 16/09/2012, 01:18 PM   #5
Ronaldo_raul™
Gangsta
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: .
Posts: 999
Reputation: 67
Default Re: Mysql Experts, take a look please.

Quote:
Originally Posted by Vince View Post
I saw it. But confused
Help.
Ronaldo_raul™ is offline   Reply With Quote
Old 16/09/2012, 01:40 PM   #6
Sinner
Gangsta
 
Sinner's Avatar
 
Join Date: Aug 2010
Location: On This Mortal Coil
Posts: 770
Reputation: 292
Default Re: Mysql Experts, take a look please.

Quote:
Originally Posted by Ronaldo_raul™ View Post
I saw it. But confused
Help.
Reserved words/keywords are just words already used by MySQL (like "update", "insert", "table", "change", etc...).
In most cases you won't even need to use backticks.
__________________
Please use the search feature before asking a question.
Sinner is offline   Reply With Quote
Old 16/09/2012, 07:20 PM   #7
Ronaldo_raul™
Gangsta
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: .
Posts: 999
Reputation: 67
Default Re: Mysql Experts, take a look please.

Quote:
Originally Posted by Sinner View Post
Reserved words/keywords are just words already used by MySQL (like "update", "insert", "table", "change", etc...).
In most cases you won't even need to use backticks.
AHA!

Got it, thank you. But I've seen many users doing -
pawn Code:
mysql_query( "SELECT `users` SET a=1, ...... ) ;

Seems that's the wrong way.

I've PM'ed you regarding some questions, please check it out.
Ronaldo_raul™ is offline   Reply With Quote
Old 16/09/2012, 08:19 PM   #8
ReneG
High-roller
 
Join Date: Oct 2011
Location: Sublime Text 2
Posts: 1,906
Reputation: 337
Default Re: Mysql Experts, take a look please.

Also, since you're just learning MySQL, learn how to use the threaded queries, with the cache. It still surprises me why some people are still using methods R6 and below, it's also faster, and easier IMO
ReneG is offline   Reply With Quote
Old 17/09/2012, 08:10 AM   #9
Ronaldo_raul™
Gangsta
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: .
Posts: 999
Reputation: 67
Default Re: Mysql Experts, take a look please.

Quote:
Originally Posted by VincentDunn View Post
Also, since you're just learning MySQL, learn how to use the threaded queries, with the cache. It still surprises me why some people are still using methods R6 and below, it's also faster, and easier IMO
Ah, Yes. Thank you.
+reps for you all.



NOTE: Topic or discussion didn't end. I want more suggestions and knowledge.
Ronaldo_raul™ is offline   Reply With Quote
Old 17/09/2012, 08:18 AM   #10
Emmet_
Guest
 
Posts: n/a
Default Re: Mysql Experts, take a look please.

There are some words that are reserved by MySQL, so doing this:

pawn Code:
mysql_query("UPDATE `accounts` SET Points = '50' ...");

Wouldn't work. Why? The word Points contains a word (int) which is reserved by MySQL.
Therefore, that query won't be executed, and an error will be logged into mysql_log.txt.

Here's the correct way:

pawn Code:
mysql_query("UPDATE `accounts` SET `Points` = '50' ...");

You must include the backtick character before and after a table/field name.
  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tool/Web/Other] MySQL DB Manager - Easily manage your MySQL databases with this remote application fiki574 Tools and Files 13 22/07/2012 10:41 AM
Graphic cards experts. DeeCaay Everything and Nothing 10 13/06/2012 01:10 PM
[Help]2 Errors Must Be Simple For Experts Onyx09 Help Archive 9 16/01/2010 06:32 AM


All times are GMT. The time now is 05:32 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.