How to pass parameters to MySQL query callback function in Node.js
P粉078945182
P粉078945182 2023-08-22 15:44:32
0
2
453
<p>I'm trying to figure out the correct way to pass custom data to a query call so it's available in the callback. I'm using MySQL library (all latest versions) in nodejs. </p> <p>I have a call connection.query(sql, function(err, result) {...});</p> <p>I can't find a way to 1) pass custom data/parameters to the call so it's available when the callback is called. So, what's the right thing to do? </p> <p>I have the following pseudocode: </p> <pre class="brush:php;toolbar:false;">... 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; }; }</pre> <p>From the code above, I need to be able to pass the current value of "ix" used in the query to the callback itself. </p> <p>How do I do this? </p>
P粉078945182
P粉078945182

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!