Re: [PHP] Mystery foreach error
On Mar 13, 2013, at 5:02 PM, David Harkness wrote: > isset() will return false for an array key 'foo' mapped to a null value > whereas array_key_exists() will return true. The latter asks "Is this key in > the array?" whereas isset() adds "and is its value not null?" While isset() > is every-so-slightly faster, this should not be a concern. Use whichever > makes sense for the context here. Hi David, Thank you for the explanation. It's nice to know the difference between them. Since they are equivalent for my use, I went with array_key_exists, simply because it makes more sense to me in English. ;) Thanks again to everyone. I got it to work _and_ there are no more errors!!! Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
2013/3/14 David Harkness > > On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs wrote: > >> Because 'null' is the representation of "nothing" array_key_exists() and >> isset() can be treated as semantically equivalent. > > > As I said, these functions return different results for null values. It > won't matter for Angela since she isn't storing null in the array, though. > Thats exactly, what I tried to say :) > > Peace, > David > > -- github.com/KingCrunch
Re: [PHP] Mystery foreach error
On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs wrote: > Because 'null' is the representation of "nothing" array_key_exists() and > isset() can be treated as semantically equivalent. As I said, these functions return different results for null values. It won't matter for Angela since she isn't storing null in the array, though. Peace, David
Re: [PHP] Mystery foreach error
2013/3/14 David Harkness > On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone > wrote: > > > I ran across if(array_key_exists) and it seems to work. How does that > > differ from if(isset($states[$state]))? > > > Hi Angela, > > isset() will return false for an array key 'foo' mapped to a null value > whereas array_key_exists() will return true. The latter asks "Is this key > in the array?" whereas isset() adds "and is its value not null?" While > isset() is every-so-slightly faster, this should not be a concern. Use > whichever makes sense for the context here. Since you don't stick null > values into the array, I prefer the isset() form because the syntax reads > better to me. > Just a minor addition: Because 'null' is the representation of "nothing" array_key_exists() and isset() can be treated as semantically equivalent. Another approach (in my eyes the cleaner one ;)) is to simply _ensure_ that the keys I want to use exists. Of course this only works in cases, where the key is not dynamical, or the dynamic keys are known, which is not the case here, it seems. $defaults = array('stateNames' => array(), 'states' => array()); $values = array_merge($defaults, $values); $values['states'] = array_merge(array_fill_keys($values['stateNames'], null), $values['states']); if (!$values[$myState]) { } > > Peace, > David > -- github.com/KingCrunch
Re: FW: [PHP] Accessing Files Outside the Web Root
"Dale H. Cook" wrote: > At 05:04 PM 3/13/2013, Dan McCullough wrote > : >>Web bots can ignore the robots.txt file, most scrapers would. > > and at 05:06 PM 3/13/2013, Marc Guay wrote: > >>These don't sound like robots that would respect a txt file to me. > > Dan and Marc are correct. Although I used the terms "spiders" and > "pirates" I believe that the correct term, as employed by Dan, is > "scrapers," and that twerm might be applied to either the robot or the > site which displays its results. One blogger has called scrapers "the > arterial plaque of the Internet." I need to implement a solution that > allows humans to access my files but prevents scrapers from accessing > them. I will undoubtedly have to implement some type of > challenge-and-response in the system (such as a captcha), but as long as > those files are stored below the web root a scraper that has a valid URL > can probably grab them. That is part of what the "public" in public_html > implies. > > One of the reasons why this irks me is that the scrapers are all > commercial sites, but they haven't offered me a piece of the action for > the use of my files. My domain is an entirely non-commercial domain, and I > provide free hosting for other non-commercial genealogical works, > primarily pages that are part of the USGenWeb Project, which is perhaps > the largest of all non-commercial genealogical projects. > readfile() is probably where you want to start, in conjunction with a captcha or similar -- Cheers David Robley Catholic (n.) A cat with a drinking problem. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone wrote: > I ran across if(array_key_exists) and it seems to work. How does that > differ from if(isset($states[$state]))? Hi Angela, isset() will return false for an array key 'foo' mapped to a null value whereas array_key_exists() will return true. The latter asks "Is this key in the array?" whereas isset() adds "and is its value not null?" While isset() is every-so-slightly faster, this should not be a concern. Use whichever makes sense for the context here. Since you don't stick null values into the array, I prefer the isset() form because the syntax reads better to me. Peace, David
Re: [PHP] Mystery foreach error
On Mar 13, 2013, at 4:24 PM, Matijn Woudt wrote: > That wouldn't work, in_array checks the values, and your states are in the > keys. Use: > if(isset($states[$state])) Hi Matijn, Before I received your email, I ran across if(array_key_exists) and it seems to work. How does that differ from if(isset($states[$state]))? Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mystery foreach error
On Thu, Mar 14, 2013 at 12:18 AM, Angela Barone wrote: > On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: > > Why not just check if the $state exists as a key of the array $states > before doing this? > > Jim, > > Are you thinking about the in_array function? > > Angela That wouldn't work, in_array checks the values, and your states are in the keys. Use: if(isset($states[$state])) - Matijn
Re: [PHP] Mystery foreach error
On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: > Why not just check if the $state exists as a key of the array $states before > doing this? Jim, Are you thinking about the in_array function? Angela
Re: [PHP] Mystery foreach error
On Wed, Mar 13, 2013 at 5:07 PM, Jim Giner wrote: > On 3/12/2013 9:04 PM, Angela Barone wrote: > >> On Mar 12, 2013, at 5:16 PM, David Robley wrote: >> >>> Presumably there is a fixed list of State - those are US states? - >>> >> >> so why not provide a drop down list of the possible choices? >>> >> >> There is, but the problem must have been that if someone didn't >> select a State, $state was blank. I've since given the "Select a State..." >> choice a value of 'XX' and I'm now looking for that in the if statement I >> mentioned before. >> >> Angela >> >> Why not just check if the $state exists as a key of the array $states > before doing this? Exactly, that's much better. It could be that some hacker enters something other than XX or one of the states..
Re: FW: [PHP] Accessing Files Outside the Web Root
At 05:04 PM 3/13/2013, Dan McCullough wrote : >Web bots can ignore the robots.txt file, most scrapers would. and at 05:06 PM 3/13/2013, Marc Guay wrote: >These don't sound like robots that would respect a txt file to me. Dan and Marc are correct. Although I used the terms "spiders" and "pirates" I believe that the correct term, as employed by Dan, is "scrapers," and that twerm might be applied to either the robot or the site which displays its results. One blogger has called scrapers "the arterial plaque of the Internet." I need to implement a solution that allows humans to access my files but prevents scrapers from accessing them. I will undoubtedly have to implement some type of challenge-and-response in the system (such as a captcha), but as long as those files are stored below the web root a scraper that has a valid URL can probably grab them. That is part of what the "public" in public_html implies. One of the reasons why this irks me is that the scrapers are all commercial sites, but they haven't offered me a piece of the action for the use of my files. My domain is an entirely non-commercial domain, and I provide free hosting for other non-commercial genealogical works, primarily pages that are part of the USGenWeb Project, which is perhaps the largest of all non-commercial genealogical projects. Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants; Plymouth Co. MA Coordinator for the USGenWeb Project Administrator of http://plymouthcolony.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: FW: [PHP] Accessing Files Outside the Web Root
At 04:58 PM 3/13/2013, Jen Rasmussen wrote: >Have you tried keeping all of your documents in one directory and blocking >that directory via a robots.txt file? A spider used by a pirate site does not have to honor robots.txt, just as a non-Adobe PDF utility does not have to honor security settings imposed by Acrobat Pro. The use of robots.txt would succeed mainly in blocking major search engines, which are not the problem. Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants; Plymouth Co. MA Coordinator for the USGenWeb Project Administrator of http://plymouthcolony.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: FW: [PHP] Accessing Files Outside the Web Root
> Have you tried keeping all of your documents in one directory and blocking > that directory via a robots.txt file? These don't sound like robots that would respect a txt file to me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: FW: [PHP] Accessing Files Outside the Web Root
Web bots can ignore the robots.txt file, most scrapers would. On Mar 13, 2013 4:59 PM, "Jen Rasmussen" wrote: > -Original Message- > From: Dale H. Cook [mailto:radiot...@plymouthcolony.net] > Sent: Wednesday, March 13, 2013 3:38 PM > To: php-general@lists.php.net > Subject: [PHP] Accessing Files Outside the Web Root > > Let me preface my question by noting that I am virtually a PHP novice. > Although I am a long-time webmaster, and have used PHP for some years to > give visitors access to information in my SQL database, this is my first > attempt to use it for another purpose. I have browsed the mailing list > archives and have searched online but have not yet succeeded in teaching > myself how to do what I want to do. This need not provoke a lengthy > discussion or involve extensive hand-holding - if someone can point to an > appropriate code sample or online tutorial that might do the trick. > > I am the author of a number of PDF files that serve as genealogical > reference works. My problem is that there are a number of sites which are > posing as search engines and which display my PDF files in their entirety > on > their own sites. These pirate sites are not simply opening a window that > displays my files as they appear on my site. They are using Google Docs to > display copies of my files that are cached or stored elsewhere online. The > proof of that is that I can modify one of my files and upload it to my > site. > The file, as seen on my site, immediately displays the modification. The > same file, as displayed on the pirate sites, is unmodified and may remain > unmodified for weeks. > > It is obvious that my files, which are stored under public_html, are being > spidered and then stored or cached. This displeases me greatly. I want my > files, some of which have cost an enormous amount of work over many years, > to be available only on my site. Legitimate search engines, such as Google, > may display a snippet, but they do not display the entire file - they link > to my site so the visitor can get the file from me. > > A little study has indicated to me that if I store those files in a folder > outside the web root and use PHP to provide access they will not be > spidered. Writing a PHP script to provide access to the files in that > folder > is what I need help with. I have experimented with a number of code samples > but have not been able to make things work. Could any of you point to code > samples or tutorials that might help me? Remember that, aside from the code > I have written to handle my SQL database I am a PHP novice. > > Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants; > Plymouth Co. MA Coordinator for the USGenWeb Project Administrator of > http://plymouthcolony.net > > > -- > PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: > http://www.php.net/unsub.php > > > Have you tried keeping all of your documents in one directory and blocking > that directory via a robots.txt file? > > Jen > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
FW: [PHP] Accessing Files Outside the Web Root
-Original Message- From: Dale H. Cook [mailto:radiot...@plymouthcolony.net] Sent: Wednesday, March 13, 2013 3:38 PM To: php-general@lists.php.net Subject: [PHP] Accessing Files Outside the Web Root Let me preface my question by noting that I am virtually a PHP novice. Although I am a long-time webmaster, and have used PHP for some years to give visitors access to information in my SQL database, this is my first attempt to use it for another purpose. I have browsed the mailing list archives and have searched online but have not yet succeeded in teaching myself how to do what I want to do. This need not provoke a lengthy discussion or involve extensive hand-holding - if someone can point to an appropriate code sample or online tutorial that might do the trick. I am the author of a number of PDF files that serve as genealogical reference works. My problem is that there are a number of sites which are posing as search engines and which display my PDF files in their entirety on their own sites. These pirate sites are not simply opening a window that displays my files as they appear on my site. They are using Google Docs to display copies of my files that are cached or stored elsewhere online. The proof of that is that I can modify one of my files and upload it to my site. The file, as seen on my site, immediately displays the modification. The same file, as displayed on the pirate sites, is unmodified and may remain unmodified for weeks. It is obvious that my files, which are stored under public_html, are being spidered and then stored or cached. This displeases me greatly. I want my files, some of which have cost an enormous amount of work over many years, to be available only on my site. Legitimate search engines, such as Google, may display a snippet, but they do not display the entire file - they link to my site so the visitor can get the file from me. A little study has indicated to me that if I store those files in a folder outside the web root and use PHP to provide access they will not be spidered. Writing a PHP script to provide access to the files in that folder is what I need help with. I have experimented with a number of code samples but have not been able to make things work. Could any of you point to code samples or tutorials that might help me? Remember that, aside from the code I have written to handle my SQL database I am a PHP novice. Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants; Plymouth Co. MA Coordinator for the USGenWeb Project Administrator of http://plymouthcolony.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Have you tried keeping all of your documents in one directory and blocking that directory via a robots.txt file? Jen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Accessing Files Outside the Web Root
Let me preface my question by noting that I am virtually a PHP novice. Although I am a long-time webmaster, and have used PHP for some years to give visitors access to information in my SQL database, this is my first attempt to use it for another purpose. I have browsed the mailing list archives and have searched online but have not yet succeeded in teaching myself how to do what I want to do. This need not provoke a lengthy discussion or involve extensive hand-holding - if someone can point to an appropriate code sample or online tutorial that might do the trick. I am the author of a number of PDF files that serve as genealogical reference works. My problem is that there are a number of sites which are posing as search engines and which display my PDF files in their entirety on their own sites. These pirate sites are not simply opening a window that displays my files as they appear on my site. They are using Google Docs to display copies of my files that are cached or stored elsewhere online. The proof of that is that I can modify one of my files and upload it to my site. The file, as seen on my site, immediately displays the modification. The same file, as displayed on the pirate sites, is unmodified and may remain unmodified for weeks. It is obvious that my files, which are stored under public_html, are being spidered and then stored or cached. This displeases me greatly. I want my files, some of which have cost an enormous amount of work over many years, to be available only on my site. Legitimate search engines, such as Google, may display a snippet, but they do not display the entire file - they link to my site so the visitor can get the file from me. A little study has indicated to me that if I store those files in a folder outside the web root and use PHP to provide access they will not be spidered. Writing a PHP script to provide access to the files in that folder is what I need help with. I have experimented with a number of code samples but have not been able to make things work. Could any of you point to code samples or tutorials that might help me? Remember that, aside from the code I have written to handle my SQL database I am a PHP novice. Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants; Plymouth Co. MA Coordinator for the USGenWeb Project Administrator of http://plymouthcolony.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Generating CRUD code for normalized db
On Wed, Mar 13, 2013 at 2:55 PM, Ashley Sheridan wrote: > On Wed, 2013-03-13 at 19:24 +0100, Marco Behnke wrote: > >> Am 13.03.13 12:57, schrieb Gary: >> > ma...@behnke.biz wrote: >> > >> >> Do us all a favor abnd stay away from open source if you do not honor >> >> the work >> >> us wannabes put into it. >> > As I said before "I wasn't aware you would feel that the cap fitted." >> > If you do feel that, then perhaps instead of complaining at me for >> > pointing it out, you would be better off employing that time increasing >> > the quality of what you produce. >> > >> So you said you tried Yii. But have you wasted some of your precious >> time trying out the extension that "extends" Yii in a way, that creating >> models and views with Gii get proper SELECT Boxes and stuff for >> relations? If I understood you correct, this is what you were looking for? >> > > > At this point I don't think he's looking for an actual solution, but > merely wants to moan about open source. OSS has flaws, of course, but > even someone so narrow minded would have a hard time arguing in earnest > that it suffered from too little choice and a lack of solutions to a > problem. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > Two minutes with google got me this: http://www.codegravity.com/programming/orm-object-relational-mapping-frameworks-php It seems that propel ( http://www.propelorm.org/ ) and CoughPHP ( http://coughphp.com/ ) both offer code generation -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql custom global defined variable
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: ma...@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz signature.asc Description: OpenPGP digital signature
Re: [PHP] Re: Generating CRUD code for normalized db
On Wed, 2013-03-13 at 19:24 +0100, Marco Behnke wrote: > Am 13.03.13 12:57, schrieb Gary: > > ma...@behnke.biz wrote: > > > >> Do us all a favor abnd stay away from open source if you do not honor > >> the work > >> us wannabes put into it. > > As I said before "I wasn't aware you would feel that the cap fitted." > > If you do feel that, then perhaps instead of complaining at me for > > pointing it out, you would be better off employing that time increasing > > the quality of what you produce. > > > So you said you tried Yii. But have you wasted some of your precious > time trying out the extension that "extends" Yii in a way, that creating > models and views with Gii get proper SELECT Boxes and stuff for > relations? If I understood you correct, this is what you were looking for? > At this point I don't think he's looking for an actual solution, but merely wants to moan about open source. OSS has flaws, of course, but even someone so narrow minded would have a hard time arguing in earnest that it suffered from too little choice and a lack of solutions to a problem. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Re: Generating CRUD code for normalized db
Am 13.03.13 12:57, schrieb Gary: > ma...@behnke.biz wrote: > >> Do us all a favor abnd stay away from open source if you do not honor >> the work >> us wannabes put into it. > As I said before "I wasn't aware you would feel that the cap fitted." > If you do feel that, then perhaps instead of complaining at me for > pointing it out, you would be better off employing that time increasing > the quality of what you produce. > So you said you tried Yii. But have you wasted some of your precious time trying out the extension that "extends" Yii in a way, that creating models and views with Gii get proper SELECT Boxes and stuff for relations? If I understood you correct, this is what you were looking for? -- Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: ma...@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz signature.asc Description: OpenPGP digital signature
Re: [PHP] Mystery foreach error
On 3/12/2013 9:04 PM, Angela Barone wrote: On Mar 12, 2013, at 5:16 PM, David Robley wrote: Presumably there is a fixed list of State - those are US states? - so why not provide a drop down list of the possible choices? There is, but the problem must have been that if someone didn't select a State, $state was blank. I've since given the "Select a State..." choice a value of 'XX' and I'm now looking for that in the if statement I mentioned before. Angela Why not just check if the $state exists as a key of the array $states before doing this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Generating CRUD code for normalized db
On 3/13/2013 7:57 AM, Gary wrote: ma...@behnke.biz wrote: Do us all a favor abnd stay away from open source if you do not honor the work us wannabes put into it. As I said before "I wasn't aware you would feel that the cap fitted." If you do feel that, then perhaps instead of complaining at me for pointing it out, you would be better off employing that time increasing the quality of what you produce. YOU ARE JUST NOT A NICE PERSON! Please go away until you learn to act like an adult. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Traits - Is it stable to use get_class_methods on a trait?
Hello All, there is a trait which sits in a class. I need the names of the trait methods, and get_class_methods does this job. I am happy with that, but is it safe/stable? Is there a better way to get trait method names? Thanks a lot. Working example (My_Class and My_Trait are in different files):. -- trait My_Trait { function trait_method_1() {} function trait_method_2() {} } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class My_Class { use My_Trait; function class_method_1() { $trait_methods = get_class_methods( 'My_Trait' ); print_r( $trait_methods ); } function class_method_2() {} } $my_object = new My_Class(); $my_object->class_method_1(); Result: [13-Mar-2013 14:41:22 UTC] Array ( [0] => trait_method_1 [1] => trait_method_2 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imap_open use to read the sent mail using gmail
On Mar 13, 2013, at 10:20 AM, Kevin Peterson wrote: > Hi, > > I am using imap_open > ("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox, $user, pass) but > want to access gmail sent box not the inbox. Please suggest how to proceed. > Use $mboxes = imap_getmailboxes($imap, "{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}, "*"); print_r($mboxes); To find mailbox names. Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql custom global defined variable
On Mar 13, 2013, at 10:35 AM, Kevin Peterson wrote: > 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 ? > 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. > Question 1: I see no possible improvements, you could however use an array with values instead of constants, but that's rather a personal choice as I don't like constants that much, unless you are on your own namespace. My example implementation: $houseTypes = array( 'house_small_type' => 0, 'house_medium_type' => 1, etc. ); Question 2: You could use ENUM data type, but it has quite a few disadvantages: 1- Translation could be tricky to implement 2- DDL shouldn't be used for data! 3- Updating or deleting values can leave your old records in an inconsistent state You can also use SET to set variables, I've never used them but I think they could work in your case: http://dev.mysql.com/doc/refman/5.5/en/user-variables.html Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql custom global defined variable
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 ? 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.