node-mysql单个值,用于多个查询参数

时间:2017-04-08 13:32:59

标签: mysql node.js prepared-statement

目前,在node.js中,如果我想在MySQL表中的多列中搜索字符串,我必须这样做:

mysqlConnection.query(
    "SELECT * FROM my_table WHERE column_a LIKE ? OR column_b LIKE ? OR column_c LIKE ?",
    [searchString, searchString, searchString],
    callback
);

我希望能够这样做:

mysqlConnection.query(
    "SELECT * FROM my_table WHERE column_a LIKE ? OR column_b LIKE ? OR column_c LIKE ?", 
    searchString, callback
);

或者甚至可能使用命名参数:

mysqlConnection.query(
    "SELECT * FROM my_table WHERE column_a LIKE :searchString OR column_b LIKE :searchString OR column_c LIKE :searchString",
    {searchString: "needle"},
    callback
);

我有办法吗?

0 个答案:

没有答案