{"_id":"5dbfcb4fc11b1e0060b8bb50","__v":2,"category":{"_id":"5dbfcb4fc11b1e0060b8bb1c","pages":["5dbfcb4fc11b1e0060b8bb4c","5dbfcb4fc11b1e0060b8bb4d","5dbfcb4fc11b1e0060b8bb4e","5dbfcb4fc11b1e0060b8bb4f","5dbfcb4fc11b1e0060b8bb50","5dbfcb4fc11b1e0060b8bb51","5dbfcb4fc11b1e0060b8bb52","5dbfcb4fc11b1e0060b8bb53","5dbfcb4fc11b1e0060b8bb54","5dbfcb4fc11b1e0060b8bb55","5dbfcb4fc11b1e0060b8bb56","5dbfcb4fc11b1e0060b8bb57"],"version":"5dbfcb4fc11b1e0060b8bb58","__v":1,"project":"55227389b4a0de0d00de7e28","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-06T11:52:42.014Z","from_sync":false,"order":0,"slug":"_","title":"コア"},"project":"55227389b4a0de0d00de7e28","version":{"_id":"5dbfcb4fc11b1e0060b8bb58","__v":1,"project":"55227389b4a0de0d00de7e28","forked_from":"5544d76ad8833c0d00582801","createdAt":"2015-05-02T13:55:54.059Z","releaseDate":"2015-05-02T13:55:54.059Z","categories":["5dbfcb4fc11b1e0060b8bb1c","5dbfcb4fc11b1e0060b8bb1d","5dbfcb4fc11b1e0060b8bb1e","5dbfcb4fc11b1e0060b8bb1f","5dbfcb4fc11b1e0060b8bb20","5dd8f4894243850024b9564b"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"4.9.0","version":"4.9"},"githubsync":"","user":"551952063414b40d00e470cb","metadata":{"title":"","description":"","image":[]},"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-06T12:02:39.362Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?u\"\n}\n[/block]\nデータを更新するための構造持つ配列を格納します:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$data = array (\\n    'payment_id' => 5\\n    );\\n$order_id = 3;\\n \\ndb_query('UPDATE ?:orders SET ?u WHERE order_id = ?i', $data, $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"UPDATE cscart_orders SET payment_id = '5' WHERE order_id = 3;\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?e\"\n}\n[/block]\nデータを挿入するための構造持つ配列を格納します:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$data = array (\\n    'payment_id' => 5,\\n    'order_id' => 3\\n);\\n \\ndb_query('INSERT INTO ?:orders ?e', $data);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"INSERT INTO cscart_orders (payment_id, order_id) VALUES ('5', '3');\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?i\"\n}\n[/block]\n文字列や数値を受け取り、整数に変換します\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$order_id = 4;\\ndb_query('SELECT * FROM ?:orders WHERE order_id = ?i', $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_orders WHERE order_id = 4;\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?s\"\n}\n[/block]\n文字列や数値を(スラッシュを追加して)文字列に変換します\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$order_id = 'adasd';\\ndb_query('SELECT * FROM ?:orders WHERE order_id = ?s', $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_orders WHERE order_id = 'foo';\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?l\"\n}\n[/block]\n受け取ったデータをLIKEオペレーターに置換するために文字列に変換します(ダブルバックスラッシュに変換されスラッシュが追加されます)\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$piece = '%black\\\\white%';\\ndb_query('SELECT * FROM ?:product_descriptions WHERE product LIKE ?l', $piece);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_product_descriptions WHERE product LIKE '%black\\\\\\\\\\\\\\\\white%';\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?d\"\n}\n[/block]\nデータをデシマル(分数)に変換する\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$order_id = '123.345345';\\ndb_query('SELECT * FROM ?:orders WHERE order_id = ?d', $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_orders WHERE order_id = '123.35';\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?a\"\n}\n[/block]\nprepares data to be used in the structure IN () as a set of strings, receives a string, number, array:\n文字列や数値、配列をIN ()で使えるデータに変換します\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$order_id = '123';\\ndb_query('SELECT * FROM ?:orders WHERE order_id IN (?a)', $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_orders WHERE order_id IN ('123');\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?n\"\n}\n[/block]\n文字列や数値、配列を`IN()`で使えるデータに変換します\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$order_id = '123.45';\\ndb_query('SELECT * FROM ?:orders WHERE order_id IN (?n)', $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?p\"\n}\n[/block]\n準備された値の挿入:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$order_id = 'order_id = 4';\\ndb_query('SELECT * FROM ?:orders WHERE ?p', $order_id);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_orders WHERE order_id = 4;\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?w\"\n}\n[/block]\nWHERE句で使えるデータを格納します\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$data = array (\\n    'payment_id' => 5,\\n    'order_id' => 3\\n);\\n \\ndb_query('SELECT * FROM ?:orders WHERE ?w', $data);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * cscart_orders WHERE payment_id = '5' AND order_id = '3';\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n**Operators**\n`?w` プレースホルダーは次のオペレーターをサポートしています: `=`, `!=`, `>`, `<`, `<=`, `>=`, `<>`, `LIKE`, `NOT LIKE`, `IN`, `NOT IN`, `NULL`\n\n配列の例\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$data = array (\\n    field => value,\\n    array(field, operator, value)\\n);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n  * `field` テーブルのフィールド名\n  * `value` 値の条件\n  * `operator` 条件のオペレーター \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?f\"\n}\n[/block]\n変数の値が有効なフィールド名かチェックします\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$data = 'payment:::at:::id';\\n \\ndb_query('SELECT * FROM ?:orders WHERE ?f = 5', $data);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SELECT * FROM cscart_orders WHERE  = 5;\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"?m\"\n}\n[/block]\nマルチインサートに対応する配列を格納します。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n$data = array(\\n    array(\\n        'payment_id' => 5,\\n        'order_id' => 3\\n    ),\\n    array(\\n        'payment_id' => 5,\\n        'order_id' => 4\\n    ),\\n);\\n \\ndb_query('INSERT INTO ?:orders ?m', $data);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n上記PHPコードは以下のSQLとなります。\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"INSERT INTO cscart_orders (payment_id, order_id) VALUES ('5', '3'),('5', '4');\",\n      \"language\": \"mysql\"\n    }\n  ]\n}\n[/block]","excerpt":"CS-Cartが行うデータベースへのリクエストは、プレースホルダーを使用して生成されます。","slug":"placeholders","type":"basic","title":"データベース・プレイスホルダー"}

データベース・プレイスホルダー

CS-Cartが行うデータベースへのリクエストは、プレースホルダーを使用して生成されます。

[block:api-header] { "type": "basic", "title": "?u" } [/block] データを更新するための構造持つ配列を格納します: [block:code] { "codes": [ { "code": "<?php\n$data = array (\n 'payment_id' => 5\n );\n$order_id = 3;\n \ndb_query('UPDATE ?:orders SET ?u WHERE order_id = ?i', $data, $order_id);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "UPDATE cscart_orders SET payment_id = '5' WHERE order_id = 3;", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?e" } [/block] データを挿入するための構造持つ配列を格納します: [block:code] { "codes": [ { "code": "<?php\n$data = array (\n 'payment_id' => 5,\n 'order_id' => 3\n);\n \ndb_query('INSERT INTO ?:orders ?e', $data);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "INSERT INTO cscart_orders (payment_id, order_id) VALUES ('5', '3');", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?i" } [/block] 文字列や数値を受け取り、整数に変換します [block:code] { "codes": [ { "code": "<?php\n$order_id = 4;\ndb_query('SELECT * FROM ?:orders WHERE order_id = ?i', $order_id);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_orders WHERE order_id = 4;", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?s" } [/block] 文字列や数値を(スラッシュを追加して)文字列に変換します [block:code] { "codes": [ { "code": "<?php\n$order_id = 'adasd';\ndb_query('SELECT * FROM ?:orders WHERE order_id = ?s', $order_id);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_orders WHERE order_id = 'foo';", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?l" } [/block] 受け取ったデータをLIKEオペレーターに置換するために文字列に変換します(ダブルバックスラッシュに変換されスラッシュが追加されます) [block:code] { "codes": [ { "code": "<?php\n$piece = '%black\\white%';\ndb_query('SELECT * FROM ?:product_descriptions WHERE product LIKE ?l', $piece);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_product_descriptions WHERE product LIKE '%black\\\\\\\\white%';", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?d" } [/block] データをデシマル(分数)に変換する [block:code] { "codes": [ { "code": "<?php\n$order_id = '123.345345';\ndb_query('SELECT * FROM ?:orders WHERE order_id = ?d', $order_id);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_orders WHERE order_id = '123.35';", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?a" } [/block] prepares data to be used in the structure IN () as a set of strings, receives a string, number, array: 文字列や数値、配列をIN ()で使えるデータに変換します [block:code] { "codes": [ { "code": "<?php\n$order_id = '123';\ndb_query('SELECT * FROM ?:orders WHERE order_id IN (?a)', $order_id);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_orders WHERE order_id IN ('123');", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?n" } [/block] 文字列や数値、配列を`IN()`で使えるデータに変換します [block:code] { "codes": [ { "code": "<?php\n$order_id = '123.45';\ndb_query('SELECT * FROM ?:orders WHERE order_id IN (?n)', $order_id);", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "?p" } [/block] 準備された値の挿入: [block:code] { "codes": [ { "code": "<?php\n$order_id = 'order_id = 4';\ndb_query('SELECT * FROM ?:orders WHERE ?p', $order_id);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_orders WHERE order_id = 4;", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?w" } [/block] WHERE句で使えるデータを格納します [block:code] { "codes": [ { "code": "<?php\n$data = array (\n 'payment_id' => 5,\n 'order_id' => 3\n);\n \ndb_query('SELECT * FROM ?:orders WHERE ?w', $data);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * cscart_orders WHERE payment_id = '5' AND order_id = '3';", "language": "mysql" } ] } [/block] **Operators** `?w` プレースホルダーは次のオペレーターをサポートしています: `=`, `!=`, `>`, `<`, `<=`, `>=`, `<>`, `LIKE`, `NOT LIKE`, `IN`, `NOT IN`, `NULL` 配列の例 [block:code] { "codes": [ { "code": "<?php\n$data = array (\n field => value,\n array(field, operator, value)\n);", "language": "php" } ] } [/block] * `field` テーブルのフィールド名 * `value` 値の条件 * `operator` 条件のオペレーター [block:api-header] { "type": "basic", "title": "?f" } [/block] 変数の値が有効なフィールド名かチェックします [block:code] { "codes": [ { "code": "<?php\n$data = 'payment@id';\n \ndb_query('SELECT * FROM ?:orders WHERE ?f = 5', $data);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "SELECT * FROM cscart_orders WHERE = 5;", "language": "mysql" } ] } [/block] [block:api-header] { "type": "basic", "title": "?m" } [/block] マルチインサートに対応する配列を格納します。 [block:code] { "codes": [ { "code": "<?php\n$data = array(\n array(\n 'payment_id' => 5,\n 'order_id' => 3\n ),\n array(\n 'payment_id' => 5,\n 'order_id' => 4\n ),\n);\n \ndb_query('INSERT INTO ?:orders ?m', $data);", "language": "php" } ] } [/block] 上記PHPコードは以下のSQLとなります。 [block:code] { "codes": [ { "code": "INSERT INTO cscart_orders (payment_id, order_id) VALUES ('5', '3'),('5', '4');", "language": "mysql" } ] } [/block]