addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [TriPUG] [mysql-144] Tripug: PHP Best Practices: SQL column prefixing

From: Simon
Sent on: Wednesday, August 18, 2010 9:11 PM
 >>> Database field names should not be prefixed with "field_" or "fld_" 
or, really, anything.
I've used column (field) prefixing to avoid ambiguity when tables with 
some common column names are joined and the data is being retrieved 
using the column names (mysql_fetch_assoc()­, mysql_fetch_object()­, etc). 
For example:

     select * from table1 left join table2 using(stocknum);

If table1 and table2 both have column 'id, what does $result['id'] 
actually refer to - or
What if both are needed ?
(rhetorical questions :)

Prefixed column names (tbl1_id and tbl2_id) avoids the issue without 
getting into numeric index type retrieves (e.g. mysql_fetch_array() ) or 
having to code unique column alias' on each select, for example:

     select as tbl1_id, as tbl2_id from table1 left 
join table2 using(stocknum);


On 8/16/[masked]:13 PM, Michael Kimsal wrote:
> Database field names should not be prefixed with "field_" or "fld_"
> or, really, anything.

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy