如何在pdo查询中使用OR?

时间:2018-05-23 07:33:09

标签: php mysql database pdo

我不知道为什么现在正在运作。我正在尽力解决这个问题,但不知道该怎么做。这是PDO的正确查询吗? 谢谢 阿拉伯糖。

$userNo = $this->test_input($data['userNo']);
$nid = $this->test_input(implode("", $data['nid']));

$query = "SELECT id FROM test_users WHERE user_no = :usr_no OR nid = :nid";

$stmt = $this->conn->prepare($query);
$stmt->execute([
      ':usr_no' => $userNo,
      ':nid' => $nid
]);

1 个答案:

答案 0 :(得分:0)

我刚在这个Nid之后添加了这一行。

并将(变量)的名称更改为$ nidInput。

就像下面一样。

--Table_B and A parameterized. They can change with parameter

INSERT INTO [Server_1].[DB_1].[dbo].[Table_A_1] (ColumnList1) 
--ColumnList has a lot of columns like Column1,Column2
SELECT ColumnList FROM [Server_2].[DB_2].[dbo].[Table_B_1] WHERE (Condition);
DELETE FROM [Server_2].[DB_2].[dbo].[Table_B_1] WHERE (Condition);


INSERT INTO [Server_1].[DB_1].[dbo].[Table_A_2] (ColumnList1) 
SELECT ColumnList FROM [Server_2].[DB_2].[dbo].[Table_B_2] WHERE (Condition);
DELETE FROM [Server_2].[DB_2].[dbo].[Table_B_2] WHERE (Condition);


INSERT INTO [Server_1].[DB_1].[dbo].[Table_A_3] (ColumnList1) 
SELECT ColumnList FROM [Server_2].[DB_2].[dbo].[Table_B_3] WHERE (Condition);
DELETE FROM [Server_2].[DB_2].[dbo].[Table_B_3] WHERE (Condition);


INSERT INTO [Server_1].[DB_1].[dbo].[Table_A] (ColumnList1) 
SELECT ColumnList FROM [Server_2].[DB_2].[dbo].[Table_B] WHERE (Condition);
DELETE FROM [Server_2].[DB_2].[dbo].[Table_B] WHERE (Condition);

现在,它工作正常。