Jump to content

dafydd

New Members
  • Posts

    4
  • Joined

  • Last visited

dafydd's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. dafydd

    Two OOPHP questions.

    Thanks, Ben & Stefan, I like the idea of using a global $cxn, but one counter-thought occurred to me: wouldn't using a global like that reduce portability? If I share my Person class as a way to share my Person database,[1] using a global "$cxn" would force other users/developers to use "$cxn" as the variable for their Database instance, right? Passing the Database instance in when the Person instance is created[2] means any variable name can hold the Database object, so long as the Database instance is created from the specified Database class. Or, am I thinking backwards? Also, Stefan, I would like to discuss inheritance more with you. In the context of my first footnote, many of the departments also track department-specific information that isn't needed or useful in a general demographics database. In cases like that, I'd like to be able to tell those departments that they can extend Person in order to also link to whatever department-specific information they need. (Er, I just realized that may mean having to pass two database connection objects... Must think about that.) If I do build Person as a base class, future versions can only add functions, not subtract, right? And, while code inside the functions can change, the returned output needs to be consistent, version over version. What else do I need to think about? (Finally, should this inheritance discussion get its own thread?) Thanks, again! dafydd [1] - The organization to which I'm contributing doesn't have good departmental access to the main volunteer database. So, departments with larger staffing needs are building their own applications, and volunteers are having to submit their demographic information to the org in general ~and~ each department with which they work. If my after-hours coding gets adopted, I reduce that inefficiency. [2] - I hate the word "instantiate." "Create an instance of" is too hard to express?
  2. dafydd

    MySQL NULL value

    NULL took some getting used to when I first started programming. NULL is not just lack of data, it's lack of data type. - An empty string is still a string. - Zero is still an integer. - The character "0" is still a character. NULL is not just the absence of data. It's also the absence of "metadata." That is "information about how the data is organized." Does that help? dafydd
  3. Writing bad PHP for 5 years.

  4. The starting point is my database connection class. $cxn = new Database(); Creating it has been educational, but I'm sure a couple of my shortcuts will make you cringe. The first is that I use associative arrays in two methods. One builds a record deletion statement, the other builds a record update statement. $cxn->deleteRecord($table, $fields); $cxn->updateRecord($table, $primaryKey, $fields); In each case, $fields is an associative array of the form fieldName => value . The method will then assemble and run the DELETE FROM or UPDATE $table SET statements. How illegal is this? Second, suppose I have a Person class that picks up its information from the database? Am I allowed to pass a Database object into it? $cxn = new Database (); $user = new Person ($cxn); Or, do I have to extend Database when I create in instance of Person? class Person extends Database () ... The first case would allow me to share a single connection among several instances of Person. The second would force me to have to create a separate connection for each instance of Person. Thanks! dafydd
  5. Good Morning! Context: I'm batch exporting a set of user data that includes user pictures. Of course, the recipient of the batch wants the pictures almost square, while I get & save the pictures in a 3:4 ratio.[1] The issue: I'm batch exporting as XML using SimpleXML. All the data is text, except for the user pictures. I need to encode them as base64. (I tried uuencode. It uses angle brackets as coding characters. The results were ... interesting, in an XML file.) Now, if I were just encoding the picture files, well and good. But, I have to put vertical black bars on either side of my pictures to meet the ~.90 ratio requirements of the export recipient. In GD, adding the bars is trivial. The hard part is going from the GD image object to a base64 encoding. I can't find any way to do it that doesn't involve saving the GD image to a temp file and then encoding that file. Has anyone else run into this? An ideas how I can directly encode a GD image object? Thanks! dafydd [1] - If standard digicam formats run to 3:4 (portrait orientation), why should I make my users' lives harder by forcing them to crop their pictures?
×
×
  • Create New...