Search code examples
phppdozend-framework2db2odbc

PDO_ODBC accessing IBM DB2 tables with special characters in the table names


I'm working on a DB2 table on as/400. I'm trying to run a basic query against it but the table name contains a . in it. For example: my.table is the table name.

The problem is that PDO believes that I'm specifying a database name my with my table name table. Hence the prepared statement is failing and saying no such table table exists in database my. Changing the table name is not an option.

What is the best way to handle a period in the table name? I've tried escaping the period but haven't had any success.

Here's some example code of my problem:

$sql= "select * from '[THE.TABLE]'";
        try {
            $statement = $this->db->query($sql);
            $results = $statement->execute();
            foreach ($results as $result) {
                print_r($result);
            }
            exit;
        }
        catch (\Exception $e)
        {
            //log issue and other stuff
        }

The application is running in Zend Framework 2.


Solution

  • I stand corrected. As aynber mentioned in a comment, the solution was to use double quotes escaped correctly. The answer could be found in the question directed towards MySQL.