How can you pass custom parameters to a MySQL query callback in Node.js? In the code below, the intention is to pass the current value of "ix" used in the query to the callback:
... for (ix in SomeJSONArray) { sql = "SELECT (1) FROM someTable WHERE someColumn = " + SomeJSONArray[ix].id; connection.query(sql, function (err, result) { ... var y = SomeJSONArray[ix].id; }; }
Using node-mysql, you can pass parameters to the query callback by including them as an array in the connection.query() function call. For example:
connection.query( 'SELECT * FROM table WHERE>
This approach automatically escapes the strings passed as parameters, ensuring secure queries.
For further guidance on parameter escaping and other aspects of node-mysql, refer to the documentation at [https://github.com/felixge/node-mysql](https://github.com/felixge/node-mysql).
The above is the detailed content of How to Pass Custom Parameters to a MySQL Query Callback in Node.js?. For more information, please follow other related articles on the PHP Chinese website!