#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Dec 28, 2009 11:03:20 GMT -8
Here is the problem:
I have a database. Standard MySQL. This has tables with different types. Any one table may contain ints, varchars, and booleans (tinyint(1)).
I have a bunch of PHP classes. These classes have variables in them that relate to the database column of the same name.
The classes have loaders in them that query the DB and place the returned values in the correct variables inside the class. This works except for in a few situations:
Boolean. In MySQL, this is really a tinyint(1), and therefore an int, not a boolean value. Timestamps. For ease of use, I am using MySQL timestamp columns BUT, I want to use UNIX timestamps in PHP.
For these two types, I could code into the loader an array of variables and what type they are (for just the two above) to do the conversions as it loads, but my question is: can I do this without having to maintain an array telling the loader what type to convert each variable to?
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Dec 28, 2009 12:33:14 GMT -8
Not for boolean. IDK what you're talking about for timestamps, but maybe strtotime() will help? I know strtotime works with DATETIME, but I thought TIMESTAMP already stored it as Unix. If not, and strtotime doesn't work with TIMESTAMP, convert it to date, then back to timestamp with strtotime.
And this doesn't sound optimized to me. =|
Since there's a table for each type, you could name the variable after the table (or vice versa).
$class->get('booleans'); // SELECT blah FROM booleans; print_r($class->booleans); // the array
Or however your class is set up.
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Dec 28, 2009 15:12:25 GMT -8
Not for boolean. IDK what you're talking about for timestamps, but maybe strtotime() will help? I know strtotime works with DATETIME, but I thought TIMESTAMP already stored it as Unix. If not, and strtotime doesn't work with TIMESTAMP, convert it to date, then back to timestamp with strtotime. And this doesn't sound optimized to me. =| Since there's a table for each type, you could name the variable after the table (or vice versa). $class->get('booleans'); // SELECT blah FROM booleans; print_r($class->booleans); // the array Or however your class is set up. Sorry for confusing post, the tables ARE NOT type-specific. I was saying that any one table may contain those any of those types. My question is not which functions for timestamps, etc. I know that stuff, but my question is if there is any way to make the varibles detect what type is coming from the database, so that tinyint(1) is stored in the object as a boolean, and a MySQL timestamp field (YYYY-MM-DD HH:MM:SS) is detected and sent through the (UNIX) timestamp functions needed.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Dec 28, 2009 15:34:42 GMT -8
Boolean would not be determinable, since it is literally an integer. The rest can be determined with is_string, is_numeric, etc. There's probably some is_timestamp too. If not, just use RegEx. \d{4}\-\d{2}\-\d{2} etc/
|
|