[thelist] Rusty PHP questions...

Jon Molesa rjmolesa at consoltec.net
Mon Oct 15 10:25:23 CDT 2007


*On Mon, Oct 15, 2007 at 10:05:34AM -0500 Tom Dell'Aringa <pixelmech at gmail.com> wrote:

> 1. One best practice is to never use SELECT * - could someone explain why,
> and tell me when this is okay if ever? Right now I am doing this:

It's ok to use SELECT *, but on large tables with a lot of fields you
can get back more information than you need for a given purpose.
Sometimes, when sorting, filtering, and grouping data, returning all
fields can give you a misrepresentation of what you're trying to get at.
It's always better to specify which fields you need.  OTOH, if your just
generating a table of informaton, and the table is pretty small, no
complex groupings or calculations then SELECT * is ok.

> 2. They are connecting to the db directly in the page code, which I know is
> a no-no - is the best way to do this simply to have an include like '
> connect.php'? Also, they are selecting the database at the top of the page
> as well - shouldn't I do this before each query, or does it matter? (top of
> page is like so)
> 
> mysql_connect("domain.com", "user", "pw") or die(mysql_error());
> mysql_select_db("db_name") or die(mysql_error());

Include is bennificial if you need to connect multiple pages to the db
and don't want to retype the connection strings everytime.

> 
> 3. Lastly, just checking that I am setting my variable correctly. They are
> appending an id onto the get string for each link, so I set it at the top of
> the page like so, so I can test for it at the section when I need it:
> 
> $raceId = $_GET['id'];
> 
$raceId = $_REQUEST['id'] will work for post or get and I believe is the
preferred way on PHP5??

-- 
Jon Molesa
http://rjmolesa.com



More information about the thelist mailing list