[英]php - db2 connection in centos6.2
我在192.168.0.xxx:xx中有db2数据库,在192.168.0.xxx(Cent OS 6.2)中有我的应用程序(PHP脚本)。 因此,我需要通过php脚本执行一些db2查询。
我相信我需要创建一个到DB2服务器的连接。 请帮我。
编辑
在使db2正常工作之前,您将必须安装libstdc ++依赖项。 做
yum install libstdc++.so.6
同样不要忘记为安装目录设置权限
chmod 777 /<installation dir>
创建与IBM DB2的新连接
resource db2_connect ( string $database , string $username , string $password [, array $options ] )
一个例子:-
<?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... ";
}
}
?>
该脚本将输出
Successfully created the table.
Insert... Insert... Insert... Insert... Insert... Insert... Insert...
请参阅说明文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.