我正在尝试构建某种类型的数据库类(所有PDO)。到目前为止,我的所有函数都在运行,但insert语句运行了两次。我真的不知道哪里出错了。当我运行带有回声的代码时,回声只出现一次所以我不认为它实际上被执行了两次......
当我将getBind
函数与其他语句一起使用时,它的工作完全正常......
代码
function insert ($p_sTable, $p_aCol, $p_aVal) {
$this->m_sQuery .= "INSERT INTO ".$p_sTable." (";
$queryCols = "";
foreach ($p_aCol as $col) { ... }
$this->m_sQuery .= $queryCols.") VALUES (";
$queryPlaceholders = "";
foreach ($p_aCol as $placeholder) {... }
foreach ($p_aVal as $p_aValtosave) { .... }
$this->m_sQuery .= $queryPlaceholders.")";
echo "m_sQuery:</br>".$this->m_sQuery;
echo "</br>print bindCol</br>";
print_r($this->m_aBindCol);
echo "</br>print bindVal</br>";
print_r($this->m_aBindVal);
return $this;
}
我在哪里召唤功能:
$db = Db::getConnection();
$arr = $db->insert("geprutsvanlisa",["kolom1","kolom2"], ["24", "24"])->getBind();
输出:m_sQuery:
INSERT INTO geprutsvanlisa (kolom1, kolom2) VALUES (:ikolom1, :ikolom2)
print bindCol
Array ( [0] => ikolom1 [1] => ikolom2 )
print bindVal
Array ( [0] => 24 [1] => 24 )
echo i:0
bindvalue(:ikolom1, 24)
echo i:1
bindvalue(:ikolom2, 24)
回显此ms查询
INSERT INTO geprutsvanlisa (kolom1, kolom2) VALUES (:ikolom1, :ikolom2)
echo this bindcol Array ( [0] => ikolom1 [1] => ikolom2 )
echo this bindval Array ( [0] => 24 [1] => 24 )