我有一列是我的表的主鍵,它可以具有變音符號或普通文本。無法在perl中使用DBI在mysql中插入變音符號文本的等效純文本
我有這2個值:
Håbo and Habo
我想在我的表中插入這兩列的值,但我得到的錯誤:
DBD::mysql::st execute failed: Duplicate entry 'Habo' for key 'PRIMARY'
正如我檢查哈博已經插入和它將兩個值都視爲相同,因此主鍵違規。
我的代碼:
$dbh = DBI->connect($dsn, $user, $pass)
or die "Unable to connect: $DBI::errstr\n";
$dbh->{'mysql_enable_utf8'}=1;
$dbh->do('SET NAMES utf8');
my $sql = sprintf "INSERT INTO search_term values(%s, %s)", $dbh->quote($search_term), "Data";
我的表描述
mysql> desc search_term;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| search | varchar(200) | NO | PRI | NULL | |
| site | varchar(500) | NO | | NULL | |
+---------------+--------------+------+-----+---------+-------+
我怎樣才能使MySQL把兩個值不同,並插入呢? 有什麼建議嗎?
您可以顯示創建表或描述輸出。 – FreudianSlip
@FreudianSlip:我做了編輯併發布了我的表的描述 – kailash19
作爲一個方面說明,優先使用引號綁定參數。它更快更安全。也總是在INSERT中指定列,否則您將依賴可能更改的表格順序的細節,並且更難理解。 '$ dbh-> prepare(「INSERT INTO search_term(search,site)VALUES(?,?)」); $ sth->執行($搜索,「數據」);' – Schwern