使用sqlite和PDO.我是PDO的新手,所以我可以在这里使用一些帮助.我收到错误:
sqlSTATE[HY000]: General error: 25 bind or column index out of range
这是我的代码:
// db.PHP function dbh($sql,$db = "",$nsx = "") { $db = ($db) ? $db : "mydb"; $db = $db.".sqlite"; try { $dbh = new PDO("sqlite:$db"); $dbh->setAttribute( PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION ); // id,title,desc,cost,album,version,added $dbh->exec("CREATE TABLE IF NOT EXISTS `products` ( `id` INTEGER PRIMARY KEY,`title` TEXT,`desc` TEXT,`cost` TEXT,`album` TEXT,`version`TEXT,`added` DATETIME )"); //$mem = new PDO('sqlite::memory'); //$mem->setAttribute( PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION ); $res = $dbh->prepare($sql); //var_dump($nsx); $res->execute($nsx); if (!is_array($nsx)) { return $res->fetchAll(); } } catch(PDOException $e) { return $e->getMessage(); } } // products.PHP $sql = "INSERT INTO `products` (title,added) VALUES (:title,:desc,:album,:version,:cost,:date)"; $nsx = array( ':title' => $i['addon']['title'][$k],':desc' => $i['addon']['desc'][$k],':cost' => $i['addon']['cost'][$k],':album' => $album,':version' => '1.0',':added' => $date,); $dbh = dbh($sql,"",$nsx);
你绑定:添加,但没有在VALUES列表中指定它:(:title,:desc,:album,:version,:cost,:date).而是指定:不受数组约束的日期.
原文链接:https://www.f2er.com/sqlite/197665.html