![](/img/trans.png)
[英]How to access PHP values in array like [“val1”,“val2”,“val3”] in loop
[英]MySQL SELECT from table where row = (SELECT val1, val2, val3, … etc.)
我想檢查行是否存在,但不告訴列名,而只告訴它值。 IE瀏覽器
+------+------+------+
|field1|field2|field3|
+------+------+------+
| abc | cba | val |
+------+------+------+
SELECT * FROM myTable WHERE ... = (SELECT 'abc', 'cba', 'val')
可能嗎?
我正在用php寫一個函數,如果這種行不存在,我想添加一行。 函數將采用n
參數,即。
addNewRowIfDoesNotExist('table1', 'abc', 'cba', 'val');
我不想修改功能的單一性,但是我需要檢查表中是否存在這樣的行。 所以我沒有傳遞列名。 因此,如何在不告知列名的情況下檢查行是否存在?
謝謝
麥克風
感謝您的評論。 我已經在網上找到了。
檢查兩個“選擇”是否等效
http://www.mysqltutorial.org/mysql-minus/
謝謝。
麥克風
如果您想了解我的意思,請前往:
function insertRecordIntoTableIfNotExist()
{
if (func_num_args() < 2)
exit("Too few arguments at insertRecordIntoTableIfNotExist()<br>");
$str = changeTableIntoStringWithCommasAndQuotes(func_get_args());
$firstComma = strpos($str, ",");
$tableName = substr($str, 0, $firstComma);
$tableName = substr($tableName, 1, strlen($tableName) - 2);
$rest = substr($str, $firstComma + 1);
$result = executeQuery("SELECT " . $rest . " MINUS SELECT * FROM " . $tableName . "_v;");
if ($result != FALSE)
if (hasRows($result))
return;
if (executeQuery("INSERT INTO " . $tableName . " VALUES(NULL, " . $rest . ");") == FALSE)
{
printWrongQuery();
exit("Error while inserting at insertRecordIntoTableIfNotExist()<br>");
}
}
在運行此功能之前,您需要指定一個新的視圖。 我的表格起初有id
,所以看來,我不接受它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.