Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel PDO with PHP_ODBC
  • Here is the current db connection config:
    'default' => array(
      'type'        => 'pdo',
      'connection'  => array(
                            'dsn'        => 'odbc:GLOBAL',
       'username'   => '',
       'password'   => '',
       'persistent' => true,
      ),
      'identifier'   => '',
      'table_prefix' => '',
      'charset'      => '',
      'enable_cache' => true,
      'profiling'    => true,
     )
    

    I've written some code in a Rest controller to simply display part information. I wanted to be sure that the connections worked before I started to do anything serious.
    $part = (int) Input::get('part');
            $query = DB::select('columns')->from('table')->where('part', $part);
            $data = $query->execute();
    if(DB::count_last_query() === 0) {
                $this->response(array('server_message' => 'No parts were found matching that request.'));
            }
            else{
              $this->response($data->as_array());   
            }
    

    The question, and the odd thing that happens, is if I set $part = 32010 it returns the dataset just fine. If I set $part = 20, which isn't in the db, it returns the "server_message" with no problems. However if I set it to certain values, lets say 1 or 61, it throws a DB exception instead. 1 and 16 also should return no results. PDOException [ 22018 ]: SQLSTATE[22018]: Invalid character value for cast specification: 0 [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Error in assignment. (SQLFetchScroll[0] at ext\pdo_odbc\odbc_stmt.c:537) Most of the searching I've done returns issues with "date" datatypes. It's almost as if at some point its converting it back to another datatype...or just not passing it through at all. Any help is appreciated!
  • Had a peek in the C++ source of the PDO ODBC driver. This looks like a bug in the PDO driver. When the SQLFetchScroll() returns SQL_NO_DATA (i.e. pointer before the first or after the last result), it will throw this error. I've seen code where this error has been commented out, and a lot of people complaining about it. So I'm not sure this is fixed in a newer version of PHP than the one you're using (if it exists).
  • I really appreciate you taking a look Harro.
    I've seen code where this error has been commented out, and a lot of people complaining about it.

    Do you see any way to comment out or code around it at this point? I'm on PHP 5.3.13 but not sure if the PDO_ODBC drivers have been updated recently. I'll do a bit of looking.
  • You can do that if you compile PHP from source, don't know if you're up for that.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion