core icon indicating copy to clipboard operation
core copied to clipboard

Handle PDO drivers (notably ODBC) which do not implement PDO::quote()

Open mtmacdonald opened this issue 12 years ago • 4 comments

Issue

When using the PDO ODBC driver, which does not implement PDO::quote, SQL syntax errors occur.

Reproduce

Connect to MySQL using the PDO ODBC driver:

'default' => array(
  'type'  => 'pdo',
  'connection' => array(
  'dsn' => 'odbc:Driver={MySQL ODBC 5.1 Driver};Server={localhost};Database={fuel_test};Uid={fuel};Pwd={****}',
  'username' => 'fuel',
  'password' => '****',
  ),
  'identifier'   => '`',
)

Create an ORM model. Try an update:

$entry = Model_User::find('first');
$entry->name = "Testing";
$entry->save();

Observe the invalid SQL query produced:

UPDATE `users` SET `name` = WHERE `id` = 

Cause

In core/classes/database/pdo/connection.php, the 'escape' method looks like this:

public function escape($value)
{
 // Make sure the database is connected
 $this->_connection or $this->connect();

 return $this->_connection->quote($value);
}

The PDO ODBC driver doesn't implement the 'quote' method.

Solution

Update the PDO driver to deal with any drivers which do not implement PDO::quote.

More info

FuelPHP forum thread

mtmacdonald avatar Dec 10 '12 16:12 mtmacdonald

@FrenkyNet any idea how to do this? How did you deal with this in Cabinet (if you did, and if not, it's an issue there too ;-))

WanWizard avatar Dec 10 '12 23:12 WanWizard

@mtmacdonald, can you check if this workaround helps?

WanWizard avatar Jan 12 '13 22:01 WanWizard

@WanWizard - thanks. I've tested this against MySQL connected through ODBC. This appears to solve the issue.

mtmacdonald avatar Jan 21 '13 14:01 mtmacdonald

@WanWizard. There were two unrelated database issues: dbs which do not support the LIMIT clause (impacts ORM) and dbs which do not support lastInsertId() (impacts sessions). Should these be registered as tickets as too?

mtmacdonald avatar Jan 21 '13 14:01 mtmacdonald