Re: [PHP] mysql custom global defined variable
[email protected] (Marco Behnke)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
Am 13.03.13 10:35, schrieb Kevin Peterson:
> In my database design, I tend to store some variable that is meant to be acting as a ROLE or TYPE as SMALLINT. For example :
>
> CREATE TABLE `house` (
> `id` int(11) NOT NULL AUTO_INCREMENT,
> `type` smallint(11) NOT NULL,
> )
>
>
> And in php, I do
>
> define('HOUSE_SMALL_TYPE', '0');
> define('HOUSE_MEDIUM_TYPE', '1');
>
> So in php, in SELECT queries I do :
>
> $this->db->query("SELECT * FROM house
> WHERE type=?;", HOUSE_SMALL_TYPE);
>
> My questions are :
> 1. In the php part, is there is a better way to do this ?
I stopped using define in favor of somehow "namespaced constants" as
const in classes. But basically there is no difference.
Advantages of using constants (which ever) are code completion to avoid
spelling errors. I see no possible improvements here.
> 2. In the mysql itself, does mysql also has global define functionality (like the define in php) ? I also want to do kind of SELECT * FROM house WHERE type = HOUSE_SMALL_TYPE in mysql query.
Maybe this is what you are looking for?
http://forums.mysql.com/read.php?98,273432,273432
--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3
Tel.: 0174 / 9722336
e-Mail: [email protected]
Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal
http://www.behnke.biz
signature.asc
(application/pgp-signature, 946 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJRQMx/AAoJEMsuiTvEJLXOhhMP/1eDnXw939Z2QSmp5PFvUkEw 4ST8YhADM+crrkUJUFWW6MoDVsFGnAneXDBMgq2swrOnbSML9Kjt1C2KEcOnZqa+ /FwDJ0Nm1L04t2rHuGU6je2NOk8p3n59E2EdMFBEsIGMu7wAd2QmZti1zY7EVv0b wrt1N+USJp8XFv8k0dOpeuT1FKA6rjjze6rnbD6e94IAqOF8lPaS20SihuBiVkys e86PYPmvLL4Ut96LEknze4Ld9mKG1Cvc2YlQpUx4MssI10Ukmjy2gKbhEXY9k1Iw Mm3DTborNUOAdysSlSt6P2GUaRv/ndG3seEUf7t70Ai6sGjciVkxFbq5cgt5Guta tqq4XfyS3YROm0jTHNevjcgjaeICAG/Cl0WNTMGzmmhZDQq4JMrgEhq++d4JBBBO +9ixAtf939iFE29ctYoz4Sm+IC6/HSK0moQjdZ6ILf2/vpW8aVsqUyYOA6Hf+z5m aCa3f7lksL22UNMQ0KaUe5OrfxQZGvkK8o4MxP2ce5PDyGhjZETLZisFZIU3l9SB Q+S1ogD7utlVune7WQlyMd7GVDEJVwYLMrE3B//ibkLa8nHJ3lLBD1k+1buBi8lr t9CwpbzlZ64MKbFlG5Nt4UiRdkwaEJpGuotjeOHa/c7aM2kMx3NPPJoRSwW/bSvl 1MD5Wcy3OSyLWFbLuTFq =ZW60 -----END PGP SIGNATURE-----