我有MariaDB 5.5.x引擎的數據庫。在數據庫我有表「項目」:
Table "items"
------------
ID |name | location | ... |
--------------------------
1 |some name1| 3;56;23;15;4; |
-----------------------
2 |some name2| 4;8;90; |
-----------------------
3 |some name3| 6;27;18;87;|
我正在尋找方式獲得身份證,當我知道location_ID fx。 「90後」。所有位置都以分號(「;」)分隔數據庫。在Zend的我曾經和它的工作:在超薄框架與MeekroDB類
where("location REGEXP '(^|[[.semicolon.]])" . $id . "([[.semicolon.]]|$)'");
我編程。我在PHP中的當前代碼:
$DB = new DB(); //MeekroDB PHP Class
$data = $DB::query("SELECT * FROM items WHERE locations REGEXP '(^|[[.semicolon.]])%s([[.semicolon.]]|$)'" , $id);
$ id是整數。我得到錯誤:
QUERY: SELECT * FROM items WHERE location REGEXP '(^|[[.semicolon.]])'1'([[.semicolon.]]|$)' ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1'([[.semicolon.]]|$)'' at line 1
任何想法是什麼錯?
謝謝朱利安!這是我所尋找的。它的工作原理: $ data = $ DB :: query(「SELECT * FROM items WHERE locations REGEXP'(^ |;)%d(; | $)'」,$ id); – user3588886 2015-04-14 05:05:32