2

I'm trying to use Firebird in my PHP application. I already managed to make interbase and Firebird PDO extensions work, and the connection is established without any problems.

But when I try to make a simple select into one of the tables (select * from filial), it always returns empty, just like there's nothing recorded in the table.

I already tested my script in another database, and it worked properly, so I guess it's not a PHP problem, but I think it has something with my database.

This is how I created the database and table with ISQL:

create database 'C:\My\Database\Path.fdb' page_size 4096 user 'myuser' password 'mypass' default character set UTF8;
connect 'C:\My\Database\Path.fdb' user 'myuser' password 'mypass';
create table filial (id int not null primary key, nome varchar(45));
insert into filial (id, nome) values (1, 'test');

When I run the 'select' query in ISQL, it returns the one inserted row. But doing it with interbase or PDO, I get an empty object.

I also tried using capital letters for the table and columns names.

What am I doing wrong?

I'm running this project in a Windows 7, with WAMP and Firebird server installed.

Interbase PHP code:

$db_server = 'localhost';
$db_user = 'SYSDBA';
$db_passw = 'masterkey';
$db_name = 'C:\Users\Joao\Firebirds\Desenvolvimento.fdb';

$host = $db_server.':'.$db_name;
$dbh = ibase_connect($host, $db_user, $db_passw);
$stmt = 'select * from filial';
$sth = ibase_query($dbh, $stmt);
while ($row = ibase_fetch_object($sth)) {
    echo $row->ID.'<br />';
}
ibase_free_result($sth);
ibase_close($dbh);

PDO PHP code:

$db_server = 'localhost';
$db_user = 'SYSDBA';
$db_passw = 'masterkey';
$db_name = 'C:\Users\Joao\Firebirds\Desenvolvimento.fdb';

$str_conn='firebird:host='.$db_server.';dbname='.$db_name;
$conn = new PDO($str_conn, $db_user, $db_passw);

$q = $conn->prepare('SELECT * FROM filial;');
$q->execute();
$dados = $q->fetchAll(PDO::FETCH_OBJ);

foreach($dados as $row){
   echo $row->ID.'<br/>';
}

As I'm working locally, I also put connection data.

0 Answers0