Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    5
    Rep Power
    0

    Firebird and PHP PDO functions


    HI,

    I'm trying to connect to a Firebird database using the PHP-PDO functions but I'cant.

    The problem is the dns that is used to connecto to.


    At PHP.NET there is an example of how to use the firebird driver with PDO:
    firebird:User=john;Password=mypass;Database=DATABASE.GDE;DataSource=localhost;Port=3050


    If my database is in c:\databases\test.gdb, what should I write to connect to the database?

    I've tried :

    'firebird:User=SYSDBA;Password=masterkey;Database=c:\databases\test.gdb;DataSource=localhost;Port=30 50';

    and other connections string and It does not work.

    Thanks in advance.
  2. #2
  3. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    538
    This works for me:
    php Code:
    <?php
    try {
       $dbh = new PDO("firebird:dbname=localhost:C:\\Programmi\\Firebird\\Firebird_2_0\\examples\\empbuild\\EMPLOYEE.F  DB", "SYSDBA", "masterkey");
       foreach ($dbh->query('SELECT COUNTRY from COUNTRY') as $row) {
         print_r($row);
       }   
       $dbh = null;  
    } catch (PDOException $e) {
       print "Error!: " . $e->getMessage() . "<br/>";
       die();
    }
     
    ?>
    Works also with c:\programmi ...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    1
    Rep Power
    0

    Angry Not data for the 1 row


    __________________
    The firebird database

    CREATE TABLE "T_TEST"
    (
    "INDEX" INTEGER NOT NULL,
    "DATE" DATE Default 'NOW' NOT NULL,
    "TEXTE" VARCHAR(30) NOT NULL,
    PRIMARY KEY ("INDEX")
    );

    _____________
    The index.php
    PHP Code:
    <?php

    $dsndb 
    'firebird:dbname=localhost:test.fdb';
    $userdb 'sysdba';
    $passdb 'password';

    try {
        
    $dbh = new PDO($dsndb$userdb$passdb);
        
        
    $sth $dbh->prepare('SELECT * from "T_TEST"');
        
    $sth->execute();

        
    $result $sth->fetch(PDO::FETCH_ASSOC);
        
    print_r($result);
        
    $result $sth->fetch(PDO::FETCH_ASSOC);
        
    print_r($result);

        
    $dbh null;

    } catch (
    PDOException $e) {
      echo 
    'Echec de la connexion : ' $e->getMessage() . "<br/>";
      die();
    }
    ?>
    __________
    The result

    Array ( [INDEX] => [DATE] => [TEXTE] => )
    Array ( [INDEX] => 2 [DATE] => [TEXTE] => Thibault )

    Comments on this post

    • pabloj disagrees : review your code
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    1
    Rep Power
    0

    No data for first row


    There is a bug i PDO for Firebird.

    see:
    http://bugs.php.net/bug.php?id=35386
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    60
    Rep Power
    16
    Originally Posted by salbefe
    I'm trying to connect to a Firebird database using the PHP-PDO functions but I'cant. The problem is the dns that is used to connecto to.
    you should try with
    PHP Code:
    $db = new PDO ("firebird:dbname=localhost:C:/path/to/pdotest.fdb"'userid''password'); 
    (notice the "localhost:" part)

    Anyway, the PDO_Firebird driver is severely lacking a lot of features. I've posted a test report here:

    http://www.alberton.info/php_pdo_firebird_status.html

    I'd recommend using the php_interbase extension until the PDO driver is actively maintained again.

    Comments on this post

    • pabloj agrees : Thanks, link added in the sticky section to your information_schema article
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    4
    Rep Power
    0
    Originally Posted by marshmallow
    __________________
    The firebird database

    CREATE TABLE "T_TEST"
    (
    "INDEX" INTEGER NOT NULL,
    "DATE" DATE Default 'NOW' NOT NULL,
    "TEXTE" VARCHAR(30) NOT NULL,
    PRIMARY KEY ("INDEX")
    );

    _____________
    The index.php
    PHP Code:
    <?php

    $dsndb 
    'firebird:dbname=localhost:test.fdb';
    $userdb 'sysdba';
    $passdb 'password';

    try {
        
    $dbh = new PDO($dsndb$userdb$passdb);
        
        
    $sth $dbh->prepare('SELECT * from "T_TEST"');
        
    $sth->execute();

        
    $result $sth->fetch(PDO::FETCH_ASSOC);
        
    print_r($result);
        
    $result $sth->fetch(PDO::FETCH_ASSOC);
        
    print_r($result);

        
    $dbh null;

    } catch (
    PDOException $e) {
      echo 
    'Echec de la connexion : ' $e->getMessage() . "<br/>";
      die();
    }
    ?>
    __________
    The result

    Array ( [INDEX] => [DATE] => [TEXTE] => )
    Array ( [INDEX] => 2 [DATE] => [TEXTE] => Thibault )


    So, how did you do to skip the first array, because i have the same problem here, and i dunno how to do it.
    Thanks

    Comments on this post

    • pabloj disagrees
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    60
    Rep Power
    16
    Originally Posted by krovomi
    So, how did you do to skip the first array, because i have the same problem here, and i dunno how to do it.
    as you could see here [1], it's a bug. While you could retrieve the record (IF the resultset contains more than one record) by reversing the order by clause and fetching the last record returned, it's so hackish that I would NOT consider this option in any case.

    Again, I'd recommend using the php_interbase extension until the PDO driver is actively maintained again.

    [1] http://bugs.php.net/bug.php?id=35386
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    4
    Rep Power
    0
    And if you have only one record, how did you do to get the result ?
    Thanx !


    Originally Posted by quipo
    as you could see here [1], it's a bug. While you could retrieve the record (IF the resultset contains more than one record) by reversing the order by clause and fetching the last record returned, it's so hackish that I would NOT consider this option in any case.

    Again, I'd recommend using the php_interbase extension until the PDO driver is actively maintained again.

    [1] http://bugs.php.net/bug.php?id=35386
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    60
    Rep Power
    16
    Originally Posted by krovomi
    And if you have only one record, how did you do to get the result ?
    again, don't use the PDO_Firebird extension, it's NOT usable at the current state: http://www.alberton.info/php_pdo_firebird_status.html

    Use the php_interbase extension instead.
  18. #10
  19. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    538
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    4
    Rep Power
    0
    Originally Posted by pabloj
    Are you FORCED to use PDO with Firebird?
    Yes, i'm forced to use PDO with firebird, that's the main reason why i'm a little bit lost.
    Anyway, there is no way to move from firebird to php_interbase ? And if yes, how to do it ?
    Thanx
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    60
    Rep Power
    16
    Originally Posted by krovomi
    Anyway, there is no way to move from firebird to php_interbase ? And if yes, how to do it?
    if you have the php_interbase extension installed, just use the ibase_* functions instead of the PDO ones ...
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    4
    Rep Power
    0
    Originally Posted by quipo
    if you have the php_interbase extension installed, just use the ibase_* functions instead of the PDO ones ...
    Ok, but i would like to know(i'm niew in PDO dev) if i could connect a firebird base with php_interbase functions or i have to change my firebird base on interbase base ?
    Thanks
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    60
    Rep Power
    16
    Originally Posted by krovomi
    Ok, but i would like to know(i'm niew in PDO dev) if i could connect a firebird base with php_interbase functions or i have to change my firebird base on interbase base ?
    er... what?

    If you want to know if php_interbase works with both InterBase AND Firebird databases, then yes.

    From the manual:

    http://www.php.net/ibase

    XLI. Firebird/InterBase Functions
  28. #15
  29. Bug Hunter
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Transylvania (Romania)
    Posts
    309
    Rep Power
    23

    Thumbs up I know pdo is unstable


    for compiling php 5.1.x with pdo support all i did at configuration time is like adding
    --with-pdo-firebird=/opt/firebird switch
    then make; make install
    Check the phpinfo() and pdo_firebird was there



    cat config.nice
    Code:
    #! /bin/sh
    #
    # Created by configure
    
    './configure' \
    '--with-apxs2=/opt/apache2.2/bin/apxs' \
    '--prefix=/opt/php5.1' \
    '--with-xml=shared' \
    '--with-pdo-mysql=/opt/mysql-5.0.18/' \
    '--with-pdo-firebird=/opt/firebird' \
    "$@"
    My home page: http://www.firebirdsql.org and work place :http://www.reea.net
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo