Mysql Experts, take a look please.
#1

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 Код:
mysql_free_results () ;
and another things like -
should we really do things like this -
pawn Код:
mysql_query ( "UPDATE `user` SET a=1 , b=2 WHERE `Name` = '%s'" ) ;
OR

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

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

Quote:
Originally Posted by Vince
Посмотреть сообщение
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 ?
Reply
#4

http://dev.mysql.com/doc/refman/5.0/...ved-words.html
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
I saw it. But confused
Help.
Reply
#6

Quote:
Originally Posted by Ronaldo_raul™
Посмотреть сообщение
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.
Reply
#7

Quote:
Originally Posted by Sinner
Посмотреть сообщение
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 Код:
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.
Reply
#8

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

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
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.
Reply
#10

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

pawn Код:
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 Код:
mysql_query("UPDATE `accounts` SET `Points` = '50' ...");
You must include the backtick character before and after a table/field name.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)