0
我有一個主鍵列其數據,包含ID所以它必須是唯一的PHP和MySQL:查詢是否存在,並創建如果不存在
的內容是這樣的
ID的格式<index>/<division>/<month in roman>/<last 2 digit of year>
我的問題是,什麼是最好的QUER y以檢查是否ID已經存在, 與
<index>+1/<division>/<month in roman>/<last 2 digit of year>
這是我的函數生成的ID
public function gen_id($id_type = "HL.BY") {
$id_num = 123;
$month = $this->romanic_number(date("n"));
$year = substr(date("Y"),-2);
$index_number = sprintf("%04d", $id_num);
$id = $index_number . "/" . $id_type . "/" . $month . "/" . $year;
return $id;
}
如果我的問題不明確創建ID請詢問
插入如果不存在http://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql –
爲什麼不讓id自動遞增?您的其他數據應該放在單獨的列中,這將很難在路上使用這些數據。 – chris85
@ chris85你的意思是自動遞增index_number?,不幸的是我需要使用以前的程序員數據庫 – stacheldraht27