在PHP中连接到DB2(从MySQL更改)

在PHP中连接到DB2(从MySQL更改),php,mysql,database,db2,Php,Mysql,Database,Db2,我有一段用PHP编写的代码,目前连接到MySQL数据库。我想更改与DB2的连接,目前的情况如下: $this->connection = db2_connect($this->db_host, $this->username, $this->pwd); if(!$this->connection) { $this->HandleDBError("failed to connect to database"); return false; }

我有一段用PHP编写的代码,目前连接到MySQL数据库。我想更改与DB2的连接,目前的情况如下:

$this->connection = db2_connect($this->db_host, $this->username, $this->pwd);
if(!$this->connection) {  
    $this->HandleDBError("failed to connect to database");
    return false;
}

if(!mysql_select_db($this->database, $this->connection)) {
    $this->HandleDBError('Failed to select database '.$this->database.' See if the database name is correct ');
    return false;
}

if(!mysql_query("SET NAMES 'UTF8'",$this->connection)) {
    $this->HandleDBError('Error setting utf8 encoding');
    return false;
}

return true;
如您所见,我做了一个小小的更改(
db2\u connect
)。DB2的
mysql\u select\u db
mysql\u query
的等价物是什么?(是的,我知道一些MySQL语句已经更新了,但它还能工作吗?需要做哪些更改?

1)的第一个参数叫做$database。这应该会给你一个提示,告诉你什么是mysql的等价物

2)直接等价于代码> MySqLyQuices()/Cys>,但是如果你有动态参数,你应该考虑使用准备好的语句。请参见php文档中关于以下内容的示例:


1)的第一个参数称为$database。这应该会给你一个提示,告诉你什么是mysql的等价物

2)直接等价于代码> MySqLyQuices()/Cys>,但是如果你有动态参数,你应该考虑使用准备好的语句。请参见php文档中关于以下内容的示例:


<?php
$animals = array(
    array(0, 'cat', 'Pook', 3.2),
    array(1, 'dog', 'Peaches', 12.3),
    array(2, 'horse', 'Smarty', 350.0),
);

$insert = 'INSERT INTO animals (id, breed, name, weight)
    VALUES (?, ?, ?, ?)';
$stmt = db2_prepare($conn, $insert);
if ($stmt) {
    foreach ($animals as $animal) {
        $result = db2_execute($stmt, $animal);
    }
}
?>