Subject Re: migrate mysql 5 php script to firebird 2.5
Author mickael.trecant
Hello ,
I ran in this question lately with PHP too and I have change to PDO
rather than the interbase library (even this work fine , I wanted also
not to have to rewrite all my code if the SGBD has to change someday ) ,
for this method the firebird PDO driver has to be enabled on your PHP
server .
First I create a class witch give me a connection object with something
like this ( name it fbConnection.class.php for example ) :
try { $db = new
PDO("firebird:dbname=localhost:C:\\Path\\to\\mydb\\myFDB.FDB", "SYSDBA",
"masterkey");} catch (PDOException $e) { print "Error!: " .
$e->getMessage() . "<br/>"; die();}
then I include this class to the script where it's needed ("include_once
' fbConnection.class.php';") , I rather create some models but in the
simplest way you can write this :
$sql="select cli_car_nom as name from tbl_client where cli_car_nom
containing '$nom_tri' ";
$ListUsers =
$db->prepare($sql);$ListUsers->setFetchMode(PDO::FETCH_ASSOC);$ListUsers\
->execute();
if (isset(ListUsers)) { foreach($ListUsers->fetchAll() as $User)
{ echo$User['NOM']; }
It's a short example but I find PDO more useful because you can choose
to get Object or array , handle easily exceptions and if the SGBD is
changing you only have to change the connection method in the connection
class .For an easiest use and to isolate the more possible , I have
directly create some methods in this connection class for query , insert
, update etc , then I have only to write something like " $db->
query('select * from client') " and I get an Object in return , that is
good for a descriptive page with a foreach loop or work with JSON too .
PHP and Firebird works great together , it's a pleasure to generate some
HTML with this couple , it's powerful and very easy to use even for a
beginner as me [:)] .
Again interbase library works but the future is ( for me ) more with
PDO and its abstract layout , this could prevent the kind of situation
you have to deal with .
I hope it will help you,
Cheers ,
Mickaƫl .

----Original Message-----
> From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Roberto Carlos
> Sent: Monday, October 22, 2012 3:45 PM
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] migrate mysql 5 php script to firebird 2.5
>
> How could I convert the following php script from mysql to firebird?
>
> //Get records from database
> $result = mysql_query("SELECT * FROM people;");
>
> //Add all records to an array
> $rows = array();
> while($row = mysql_fetch_array($result))
> {
> $rows[] = $row;
> }
>
> //Return result to jTable
> $jTableResult = array();
> $jTableResult['Result'] = "OK";
> $jTableResult['Records'] = $rows;
> print json_encode($jTableResult);
>
>
> thanks for any help.
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item on the
main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>



[Non-text portions of this message have been removed]