[GLLUG] Retrieving a row from mysql

jason D. Justman justmanj at msu.edu
Tue Feb 17 23:35:36 EST 2004


as rodney hampton suggested about using a database abstraction mechanism 
(or, if you are really 'reet, write your own if you ever need to do load 
balancing with mysql).  ado sends shivvers down my spine, but the pear's 
dbi design is pretty decent.  you'll find that doing:

mysql_query(....) or die("error")

gets very tedious, and a consistant entry and failure mode for this case 
saves you a lot of time down the road.  likewise, the population of a 
result set container will make your life happy, as in never having to 
type in multipe mysql_fetch_container/mysql_fetch_object - thus 
transferring your focus of database i/o to integration with your 
application.

but in general, "total_games AS total_games" isn't need since you aren't 
renaming, using as an alias, or doing a join which might shadow upon 
return to php.

likewise, adding an index on player_name in your stats table would be a 
good idea, since you'll probably be using that.

also, again, its really confusing to see $stats_table.  trust me, unless 
you have some amazing need for it - dont use it.  it just makes 
maintnence that much harder down the line since there shouldnt need to 
be more than one stats table.  any other table that extends the stats 
table should be designed for extension, not replacement (again, a proper 
design is helpful here in ensuring proper referential integreity).

j
Seth Bembeneck wrote:

>  
>
> $player_query = mysql_query("SELECT player_name AS player_name,
>
>                              total_games AS total_games,
>
>                              squad_id AS squad_id
>
>                              FROM $stats_table
>
>                              WHERE id='$id' AND accnum='$accnum'
>
>                              LIMIT 1") or die(mysql_error());
>
>  
>
>  
>
> All I did to the above query was to add the AND accnum='$accnum' to 
> the WHERE clause. That is all I have done through out the whole
>
> Application, and modified the table structures (see below). Before I 
> added all the stuff for accnum, this worked perfectly.
>
>  
>
> Seth
>
>  
>
> There are 9 tables total, this is just one of them. All I did to the 
> others was to add the accnum field.
>
>  
>
> STATS TABLE (taken from a php script):
>
>  
>
> $query = mysql_query("CREATE TABLE $stats_table (  id smallint(5) 
> unsigned NOT NULL auto_increment,
>
>   player_name varchar(16) NOT NULL default '',
>
>  .....
>
>  .....
>
>  .....
>
>  .....
>
>   last_played datetime NOT NULL default '0000-00-00 00:00:00',
>
>   squad_id int(11) NOT NULL default '0',
>
>   accnum char(10) NOT NULL default '',
>
>   PRIMARY KEY  (id),
>
>   UNIQUE KEY id (id),
>
>   KEY id_2 (id)
>
> );") or die(mysql_error());
>
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>linux-user mailing list
>linux-user at egr.msu.edu
>http://www.egr.msu.edu/mailman/listinfo/linux-user
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.egr.msu.edu/mailman-archives/linux-user/attachments/20040217/b249e867/attachment.htm


More information about the linux-user mailing list