Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2006, 05:49 PM
salbefe salbefe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 5 salbefe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 32 sec
Reputation 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.

Reply With Quote
  #2  
Old February 20th, 2006, 05:23 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,906 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 7 h 8 m 35 sec
Reputation Power: 279
This works for me:
php Code:
Original - php Code
  1. <?php
  2. try {
  3.    $dbh = new PDO("firebird:dbname=localhost:C:\\Programmi\\Firebird\\Firebird_2_0\\examples\\empbuild\\EMPLOYEE.FDB", "SYSDBA", "masterkey");
  4.    foreach ($dbh->query('SELECT COUNTRY from COUNTRY') as $row) {
  5.      print_r($row);
  6.    }   
  7.    $dbh = null
  8. } catch (PDOException $e) {
  9.    print "Error!: " . $e->getMessage() . "<br/>";
  10.    die();
  11. }
  12.  
  13. ?>
Works also with c:\programmi ...

Reply With Quote
  #3  
Old March 7th, 2006, 05:17 PM
marshmallow marshmallow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 marshmallow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 51 sec
Reputation 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

Reply With Quote
  #4  
Old March 24th, 2006, 08:03 AM
serenityNow serenityNow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 serenityNow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 54 sec
Reputation Power: 0
No data for first row

There is a bug i PDO for Firebird.

see:
http://bugs.php.net/bug.php?id=35386

Reply With Quote
  #5  
Old April 12th, 2006, 09:19 AM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
Quote:
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

Reply With Quote
  #6  
Old May 4th, 2006, 09:25 AM
krovomi krovomi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 4 krovomi New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 35 m 56 sec
Reputation Power: 0
Quote:
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!

Reply With Quote
  #7  
Old May 6th, 2006, 02:54 AM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
Quote:
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

Reply With Quote
  #8  
Old May 29th, 2006, 02:28 AM
krovomi krovomi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 4 krovomi New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 35 m 56 sec
Reputation Power: 0
And if you have only one record, how did you do to get the result ?
Thanx !


Quote:
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

Reply With Quote
  #9  
Old May 29th, 2006, 03:36 AM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
Quote:
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.

Reply With Quote
  #10  
Old May 29th, 2006, 03:58 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,906 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 7 h 8 m 35 sec
Reputation Power: 279
Quote:
Originally Posted by krovomi
And if you have only one record, how did you do to get the result ?
Thanx !
Are you FORCED to use PDO with Firebird?

Reply With Quote
  #11  
Old May 30th, 2006, 06:11 AM
krovomi krovomi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 4 krovomi New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 35 m 56 sec
Reputation Power: 0
Quote:
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

Reply With Quote
  #12  
Old May 30th, 2006, 06:17 AM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
Quote:
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 ...

Reply With Quote
  #13  
Old June 6th, 2006, 10:58 AM
krovomi krovomi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 4