🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #1427

Re: Script en PHP

#1427
From: Cristian Gutierrez
Date: Mon, 14 Aug 2006 18:00
37 lines
1887 bytes
Hoy en la tarde, T. Q. LEO dijo:

[...]

> select * from lider where cliente='$empresa' and
> MONTH(FROM_UNIXTIME(fecha))='$mescons' and
> YEAR(FROM_UNIXTIME(fecha))='$anocons' order by fecha DESC LIMIT
> ".$st.",".$pp;

Una sugerencia de estilo: es m�s legible (y hasta dir�a que un poco m�s
mantenibile) usar `sprintf' para componer sentencias SQL:

,----
| $template =<<<ENDOFTEMPLATE;
| 
| SELECT *
| FROM lider
| WHERE cliente = '%s'
|   AND MONTH(FROM_UNIXTIME(fecha)) = '%s'
|   AND YEAR(FROM_UNIXTIME(fecha))  = '%s'
| ORDER BY fecha
| DESC LIMIT %d,%d
| 
| ENDOFTEMPLATE
| 
| $query = sprintf($template,
|                  $empresa, $mescons, $anocons, $st, $pp);
`----

Lo ideal seria usar �prepared statements�, pero no siempre est�n
disponibles (entiendo que para PHP5 + MySQL 4.1 s�).

Salu2,

-- 
Guti
Code runs faster when Chuck Norris watches it.
Technical Details
Message-ID: <87fyfzi4dm.fsf@guti.cl>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news.nivel5.cl!news.cec.uchile.cl!not-for-mail
References: <44e09fc4$1_1@nova.entelchile.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,68886b01d65beeee
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news.nivel5.cl!news.cec.uchile.cl!not-for-mail
From: Cristian Gutierrez <crgutier@dcc.uchile.cl>
Newsgroups: chile.comp.programacion
Subject: Re: Script en PHP
Date: Mon, 14 Aug 2006 14:00:53 -0400
Organization: DCC/Uchile
Lines: 37
Message-ID: <87fyfzi4dm.fsf@guti.cl>
References: <44e09fc4$1_1@nova.entelchile.net>
NNTP-Posting-Host: vpn-client-029.cec.uchile.cl
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: localhost.localdomain 1155578454 10097 172.17.35.29 (14 Aug 2006 18:00:54 GMT)
X-Complaints-To: news@localhost.localdomain
NNTP-Posting-Date: Mon, 14 Aug 2006 18:00:54 +0000 (UTC)
User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)
Cancel-Lock: sha1:ulWPZZv83oQPDPIKlIjNVNIhDd8=