Name: Anonymous 2010-01-05 23:16
* For the record, I agree that PHP isn't the best. Sucks, even.
I have an OOP (object-oriented problem) and I'm wondering if either:
a) there's a solution
b) I'm worrying about nothing
I'm working on a ticketing system with MySQL. I have a child table that is one-to-one that represents ticket categories. I use it to resolve ticket category ids into English names.
I'm using my own sorta-ORM approach as I don't want to use a library. For Ticket objects, it made more sense to me to use a prepared PDO statement and execute it every time I instantiate, since it's lazy and the number of Tickets that will need to be instantiated changes depending on the page. Here's the class:
However, with the simple category name resolution table, this approach seems like a lot of unnecessary overhead, when I could get all that shit with a simple
So what's the problem?
Well, I want to take advantage of Type Hinting when I need to insert. I use a different class for creating new tickets:
I want to make sure that the value passed as
What would you do, /prog/? Aside from reading SICP, of course.
(In my next post, I'll describe what I have at the moment, and some ideas.)
I have an OOP (object-oriented problem) and I'm wondering if either:
a) there's a solution
b) I'm worrying about nothing
I'm working on a ticketing system with MySQL. I have a child table that is one-to-one that represents ticket categories. I use it to resolve ticket category ids into English names.
I'm using my own sorta-ORM approach as I don't want to use a library. For Ticket objects, it made more sense to me to use a prepared PDO statement and execute it every time I instantiate, since it's lazy and the number of Tickets that will need to be instantiated changes depending on the page. Here's the class:
class TicketORM extends TicketBase
{
private static $stmt_select;
function __construct($id)
{
if(!isset(self::$stmt_select)) {
$dbh = $this->getConnection();
try {
self::$stmt_select = $dbh->prepare(
'SELECT
...
FROM
tickets
AS t
LEFT JOIN
ticket_categories
AS tc
ON t.category_id = tc.id
WHERE
t.id = ?');
//...
}
catch (PDOException $e) {
//...
}
}
self::$stmt_select->execute( array($id) );
$result = self::$stmt_select->fetch();
$this->id = $id
$this->created = strtotime($result['created']);
//...
}
//...
}However, with the simple category name resolution table, this approach seems like a lot of unnecessary overhead, when I could get all that shit with a simple
SELECT * FROM ticket_categories.So what's the problem?
Well, I want to take advantage of Type Hinting when I need to insert. I use a different class for creating new tickets:
class Ticket extends TicketBase
{
private static $stmt_insert;
function __construct($subject, TicketCategory $category, Client $client)
{
$dbh = $this->getConnection();
self::$stmt_insert = $dbh->prepare(/* ... */);
$this->category = //?!?!?!?
//...
}
//...
}I want to make sure that the value passed as
$category is valid, in the most straightforward, db efficient, and Don't Repeat Yourself way I can. What would you do, /prog/? Aside from reading SICP, of course.
(In my next post, I'll describe what I have at the moment, and some ideas.)