Page 1 sur 1

connexion à une base DB2

Posté : 24 janv. 2007, 18:26
par donny
Salut,

Est-il possible de se connecter à une base DB2 avec php ?
si oui,pour se connecter à une base db2 via php, je dois utiliser
odbc_connect ?

je dois le parametrer comment,je ne trouve pas de doc
comme ceci
odbc_connect(NomdeMaBaseDB2, NomdeLinstance, NomDelaConnexionOdbc); ???

Merci de vos reponses
si vous avez de la doc ou une experience à me faire partager je suis preneur
je debute

Posté : 24 janv. 2007, 18:30
par Ajoloca
Bonjour,

Si tu utilises PHP 5, je te conseille de t'orienter vers PDO (PhpDataObject)

Posté : 25 janv. 2007, 09:56
par Invité
je viens de telecharger easyphp 1.8
est ce que ça correspond à la version 5 ?
et si non existe il une autre solution que PDO (PhpDataObject)

Posté : 25 janv. 2007, 10:46
par donny
personne en voit ?

Posté : 25 janv. 2007, 10:52
par donny
je viens de trouver ce site
http://www.php.documentation.givah.fr/? ... nnect.html

il parle d'un db2_connect
donc j'ai essayer et j'ai se message d'erreur
Fatal error: Call to undefined function: db2_connect() in c:\program files\easyphp1-8\www\test\db2.php on line 6
???

Posté : 25 janv. 2007, 11:24
par ouckileou
easyphp 1.8 est en PHP 4, exécute ce code pour avoir toutes les infos :
<?php
phpinfo();
?>
Les fonctions DB2 ne sont pas accessibles par défaut, généralement toutes les infos sont dans la doc : http://fr.php.net/manual/fr/ref.ibm-db2.php

Posté : 25 janv. 2007, 12:28
par donny
je me suis connecté avec odbc_connect
odbc_connect (nomdemasourceODBC,user,passwd);

Posté : 25 janv. 2007, 13:06
par mere-teresa
Si tu souhaites avoir un serveur de développement en local sur ta machine en PHP5 oriente toi vers WampServer.

Re: connexion à une base DB2

Posté : 28 févr. 2012, 15:33
par Nouvou
There seems to be a lot of good documentation
for Linux users compiling PHP with DB2 support,
but decent Windows notes are minimal.

You do not need to install full DB2 clients to get DB2
working with DB2, all you need is the IBM Data
Server Driver for ODBC, CLI, and .NET which is only
16.1 meg.

You can download the driver from here:

Direct Link:
ftp://ftp.software.ibm.com/ps/products/ ... englsh-us/
db2_v95/dsdriver/fp2/v9.5fp2_nt32_dsdriver_EN.exe

Home Page:
http://www-01.ibm.com/support/docview.w ... wg21287889

This includes both the drivers required and the PHP
dll php_ibm_db2_5.2.2.dll

Once installed the drivers do not setup the correct
path environmental variable,
so add the following to your path:

C:\Program Files\IBM\IBM DATA SERVER DRIVER\bin

Once thats done all should work! No massive
400meg client downloads required.

Whats even better about these drivers is that you
dont need to install them,
you can simply copy the bin directory to any server,
add it to your path and it will just work.
This is great for anyone developing PHP-GTK applications,
I copy the bin directory into my php-gkt2 directory
and execute using the following batch script:

path = %PATH%;.\IBM DATA SERVER DRIVER\bin
php-win.exe %*

This lets me role out lightweight DB2 client desktop
apps that dont have to be installed,
can just be coppied from PC to PC or ran over a
network or from USB stick.

As your only installing the client drivers you wont be
able to catalog databases,
so always use the full connection string. Here is a
quick bit of code to get you started:

$database = 'databasename';
$user = 'user';
$password = 'password';
$hostname = '127.0.0.1';
$port = 50000;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;".
"PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');

$query = 'SELECT * FROM TABLE';
$res = db2_prepare($conn, $query);
db2_execute($res);

while ($row = db2_fetch_array($res)) {
print_r($row);
}
thanks for all :mrgreen: