1. 查看firebird 官方文档说明
2. 链接方式有两种 InterBase 和PDO_Firebird,还有ODBC (需要指定驱动,驱动又是windows下的 放弃这种方式)
3. 最终决定使用PDO_Firebird
1. 宝塔扩展中不带 PDO_firebird,需要手动安装
2. 重点!!!! 从扩展网站下载PDO_FIREBird 在安装是存在各种问题!!什么 未定义 function **
3. 我的方法, 从php官网上下载php73源码 使用源码中的ext中带的扩展程序进行编译安装
4. 开始安装
5. yum -y install firebird-dev*
6. cd php/source/path/ext/pdo_firebird
7. /www/server/php/73/bin/phpize
8. ./configure --with-pdo-firebird --with-php-config=/www/server/php/73/bin/php-config
9. make && make install
10.# 为了确保可用 先进入php.ini 进场查看 如果extentsion_dir有定义那么可以直接这样写 否则需要带路径
10. echo "extension = pdo_firebird.so" >> /www/server/php/73/etc/php.ini
11. 重启服务检查pdo 驱动是否增加 firebird 如果有就OK了
查询
// databasePATH: 绝对路径
$dsn = 'firebird:dbname=192.168.2.4:databasePATH;charset=GB2312;';
$username = 'SYSDBA';
$password = 'masterkey';
$result = array();
try {
// Connect to database
$dbh = new \PDO($dsn, $username, $password,
[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
$sql = 'SELECT * FROM TABLE';
// Execute query
$query = $dbh->query($sql);
// Get the result row by row as object
while ($row = $query->fetch(\PDO::FETCH_OBJ)) {
$temp["NAME"] = iconv("GB2312", "UTF-8", $row->NAME);
$temp["ID"] = $row->ID;
$temp["NO"] = $row->NO;
array_push($result, $temp);
}
$query->closeCursor();
} catch (\PDOException $e) {
return error("6120 Conect error", $e->getMessage(),400);
}
写入 参考官方代码
$dsn = 'firebird:dbname=localhost:example;charset=utf8;';
$username = 'SYSDBA';
$password = 'masterkey';
try {
// Connect to database
$dbh = new \PDO($dsn, $username, $password,
[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
$sql = 'INSERT INTO users(login, email) VALUES(:login, :email)';
$users = [
[":login" => "user1", ":email" => "user1@gmail.com"],
[":login" => "user2", ":email" => "user2@gmail.com"]
];
// Prepare statement
$query = $dbh->prepare($sql);
// Execute statement
foreach ($users as $user)) {
$query->execute($user);
}
} catch (\PDOException $e) {
echo $e->getMessage();
}