2016-08-09 4 views
0

Ich habe db2-Datenbank in 192.168.0.xxx: xx und meine Anwendung (PHP-Skript) in 192.168.0.xxx (Cent OS 6.2). Also muss ich einige db2 Abfragen über das PHP-Skript ausführen.php - db2 Verbindung in Centos6.2

  • PHP 5.3.3
  • CentOS Release 6.2 (Final)
  • LSB Version: core-4.0-ia32: Kern-4.0-noarch: Grafik-4.0-ia32: Grafik -4.0-noarch: Druck-4.0-ia32: Druck-4.0-noarch
  • DATABASE IBM DB2 10.1 X64

Ich glaube, dass ich eine Verbindung zu DB2-Server erstellen muss. Bitte helfen Sie mir dabei.

Antwort

0

EDIT
Sie haben db2 libstdC++ Abhängigkeit installieren, bevor sie zu arbeiten. Sie

yum install libstdc++.so.6 

Vergessen Sie auch nicht die Berechtigungen für die Installation dir zu setzen

chmod 777 /<installation dir> 

Um eine neue Verbindung zu einem IBM DB2

resource db2_connect (string $database , string $username , string $password [, array $options ]) 

Beispiel zu erstellen: -

<?php 
$conn = db2_connect($database, $user, $password); 

// Create the test table 
$create = 'CREATE TABLE animals (id INTEGER, breed VARCHAR(32), 
    name CHAR(16), weight DECIMAL(7,2))'; 
$result = db2_exec($conn, $create); 
if ($result) { 
    print "Successfully created the table.\n"; 
} 

// Populate the test table 
$animals = array(
    array(0, 'cat', 'Pook', 3.2), 
    array(1, 'dog', 'Peaches', 12.3), 
    array(2, 'horse', 'Smarty', 350.0), 
    array(3, 'gold fish', 'Bubbles', 0.1), 
    array(4, 'budgerigar', 'Gizmo', 0.2), 
    array(5, 'goat', 'Rickety Ride', 9.7), 
    array(6, 'llama', 'Sweater', 150) 
); 

foreach ($animals as $animal) { 
    $rc = db2_exec($conn, "INSERT INTO animals (id, breed, name, weight) 
     VALUES ({$animal[0]}, '{$animal[1]}', '{$animal[2]}', {$animal[3]})"); 
    if ($rc) { 
     print "Insert... "; 
    } 
} 
?> 

Dieses Skript wird ausgegeben

Successfully created the table. 
Insert... Insert... Insert... Insert... Insert... Insert... Insert... 

Siehe documentation

+0

Hallo Tony, vielen Dank für die schnelle Antwort, aber ich habe das Skript und arbeitet über Xampp (Windows-Plattform) in Ordnung. Jetzt muss ich das gleiche in CentOS 6.2 implementieren und würde gerne wissen, ob irgendeine zusätzliche Konfiguration nötig ist, um es in Centos zu machen –