我已經加入另一位開發人員使用Zend Framework處理項目,並且我無法獲得任何數據庫插入語句在本地機器上工作。出於測試目的,我使用root用戶,我可以讓所有其他語句工作。Zend Framework - 由於空的主鍵導致PDO插入不工作
我的配置是nginx 1.6.2,PHP版本5.5.18和PDO Mysql API版本5.6.21。
服務器配置的Apache 2.0,PHP版本5.4.22和PDO Mysql的API版本34年5月5日
的問題是每一次我嘗試插入一行到數據庫中,我得到一次這樣
錯誤Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'id_client' at row 1'
在這種情況下,我嘗試使用下面的代碼,這是Zend的非常標準的中插入一行到$table
client
:
$this->_db->insert ($table, $values);
$id = $this->_db->lastInsertId();
這是數組$values
我試圖插入
array (size=13)
'id_client' => string '' (length=0)
'id_profile' => string '2' (length=1)
'status' => string '1' (length=1)
'client' => string 'ABC' (length=3)
'contact' => string 'Fred' (length=4)
'phone' => string '0412345678' (length=10)
'address' => string 'Sydney Rd' (length=6)
'suburb' => string 'Sydney' (length=6)
'state' => string 'New South Wales' (length=15)
'post_code' => string '2000' (length=4)
'notas' => string '' (length=0)
'bg' => string '#FEAF1D' (length=7)
'logo' => string '' (length=0)
這是表client
數據庫結構,顯示了在年底
CREATE TABLE IF NOT EXISTS `client` (
`id_client` int(20) NOT NULL,
`client` char(100) COLLATE utf8_spanish_ci DEFAULT NULL,
`contact` char(20) COLLATE utf8_spanish_ci DEFAULT NULL,
`phone` char(20) COLLATE utf8_spanish_ci DEFAULT NULL,
`address` char(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`suburb` char(30) COLLATE utf8_spanish_ci DEFAULT NULL,
`state` char(20) COLLATE utf8_spanish_ci DEFAULT NULL,
`post_code` char(6) COLLATE utf8_spanish_ci DEFAULT NULL,
`county` char(20) COLLATE utf8_spanish_ci DEFAULT NULL,
`notas` text COLLATE utf8_spanish_ci,
`logo` varchar(200) COLLATE utf8_spanish_ci DEFAULT NULL,
`bg` char(10) COLLATE utf8_spanish_ci DEFAULT NULL,
`id_profile` int(2) DEFAULT NULL
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
ALTER TABLE `client`
ADD PRIMARY KEY (`id_client`), ADD KEY `id_profile` (`id_profile`);
正如你可以在看到主鍵id_client
$values
數組沒有值id_client
這就是爲什麼我得到錯誤,但在zend框架(和其他人)插入語句應仍然工作,因爲數據庫將自動分配一個基於AUTO_INCREMENT
的值。這就是它在服務器上的工作方式,但是我的本地主機上沒有這樣做。
任何幫助,將不勝感激。
從陣列中刪除id_client – dixromos98 2014-10-29 07:19:44