0

If I use PDO and use FETCH_INTO like

...
$query->setFetchMode(PDO::FETCH_INTO, $this);
$query->execute();

I have a little problem. PHP variables are camelCase, but MySQL column names are with underscores. So I have creationDate vs creation_date.

Should I rename one side of equation to match the other one or do some 1:1 "mapping" via __set magic method (with switch command)?

1 Answer 1

2

Take a look at symfony's sfInflector class it does the same job (in camelize method):

http://trac.symfony-project.org/browser/branches/1.4/lib/util/sfInflector.class.php

Here's the extracted code:

$tmp = $lower_case_and_underscored_word;
$tmp = sfToolkit::pregtr($tmp, array('#/(.?)#e'    => "'::'.strtoupper('\\1')",
                                     '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));

And the code from sfToolkit:

public static function pregtr($search, $replacePairs)
{
  return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.