473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Re: MySQL Database problem (probably already solved in a message, but this is somewhat urgent)

On Sun, 12 Oct 2008 15:01:10 -0400, sheldonlg <sheldonlgwrote in
<7b******************************@giganews.com>:
>
For your case you will want something like

$sql = "SELECT * FROM tablename
WHERE FSR=" . $FSR .
" AND Password='" . $Password . '";
"SELECT *" is a bad habit. Since he wants those two fields only, it
should be "SELECT FSR, Password FROM tablename WHERE FSR = $FSR AND
Password = '$Password'". Note that I'm assuming that FSR is a numeric
field here. If not, it should also be surrounded by single quotation
marks.

Reasons:

1. "SELECT *" returns all columns from the table, whether you need
them or not. Right now the table may contain only those two columns,
but that can change in the future. Why retrieve more data than you
need?

2. If the table is changed so that one of those two columns is
renamed, replaced or deleted, "SELECT *" won't fail until you try to
access the column in question, whereas "SELECT FSR, Password" will
fail on the mysql_query call, giving you a much better idea of where
the problem is.

One can argue that it doesn't matter much in this particular case, but
keep in mind that we're talking about habits here, which are only
effective when used consistently. You're also giving advice to
someone who seems to know little or nothing about relational
databases, so they don't know what the impact of "SELECT *" is and
won't automatically correct for it when writing their own code the way
an experienced programmer would.

Here are a few articles on good SQL practices that agree with me:

<http://www.sql-server-performance.com/articles/dev/sql_best_practices_p1.aspx>
<http://sheeri.com/archives/104>
<http://mapiles.com/2008/01/18/11-best-practices-in-making-sql-queries/>
<http://www.extremeexperts.com/sql/articles/BestPractices.aspx>
<http://www.sommarskog.se/dynamic_sql.html#Dyn_table(something of a
side note)
--
Charles Calvert | Web-site Design/Development
Celtic Wolf, Inc. | Software Design/Development
http://www.celticwolf.com/ | Data Conversion
(703) 580-0210 | Project Management
Oct 13 '08 #1
0 1170

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
1
by: Matthew Clubb | last post by:
Hi, I need help developing an expanding form I've decided that a use of PHP, Mysql and Javascript is the best platform for creating a selection of database interfaces which I'm trying to build...
17
by: chicha | last post by:
Hey people, I have to convert MS Access 2000 database into mysql database, the whole thing being part of this project I'm doing for one of my faculty classes. My professor somehow presumed I...
12
by: timothy.williams | last post by:
Hi. I have a Python program that parses a file and inserts records into a database with MySQLdb. I recently upgraded to MySQL 5.0.8, and now my parser runs *really* slow. Writing out to CSV...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
2
by: Dudu | last post by:
Dear Programmers I try to install mysql version 5.0 and I encountered with a problem when I tried to start the service. I got error 1067. I checked the log file and saw the following records...
5
by: Frances | last post by:
a few days ago I installed XAMPP in my Windows 2000 machine, it completely messed my existing MySQL installation.. I've had it installed for over a year now (4.1) have never had any problems with...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
1
by: Rankin | last post by:
Oh, and I forgot to mention, I've tested the MySQL query using a MySQL client, and connecting to it from 4 different WAN-side IPs, I've been able to get the same result, which is a table with 2...
6
by: Bobby Edward | last post by:
Using ASP.NET 3.5 and MySQL (thru DevArt MyDirect.NET)... On the production server I get a "Parser Error" for every XSD dataset. It works perfect on my dev machine. But, on the production...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.