@@ -537,12 +537,11 @@ space for a new connection to be created on the next getConnection call.
537
537
538
538
## Performing queries
539
539
540
- In the MySQL library, the most basic way to perform a query is to call
541
- the ` .query() ` method on an object (like on a ` Connection ` , ` Pool ` , ` PoolNamespace `
542
- or other similar objects).
540
+ The most basic way to perform a query is to call the ` .query() ` method on an object
541
+ (like on a ` Connection ` , ` Pool ` , ` PoolNamespace ` or other similar objects).
543
542
544
- The simplest form on query comes as ` .query(sqlString, callback) ` , where a string
545
- of a MySQL query is the first argument and the second is a callback:
543
+ The simplest form of . ` query() ` is ` .query(sqlString, callback) ` , where a SQL string
544
+ is the first argument and the second is a callback:
546
545
547
546
``` js
548
547
connection .query (' SELECT * FROM `books` WHERE `author` = "David"' , function (error , results , fields ) {
@@ -552,8 +551,8 @@ connection.query('SELECT * FROM `books` WHERE `author` = "David"', function (err
552
551
});
553
552
```
554
553
555
- The second form ` .query(sqlString, parameters , callback) ` comes when using
556
- placeholders (see [ escaping query values] ( #escaping-query-values ) ):
554
+ The second form ` .query(sqlString, values , callback) ` comes when using
555
+ placeholder values (see [ escaping query values] ( #escaping-query-values ) ):
557
556
558
557
``` js
559
558
connection .query (' SELECT * FROM `books` WHERE `author` = ?' , [' David' ], function (error , results , fields ) {
@@ -580,6 +579,24 @@ connection.query({
580
579
});
581
580
```
582
581
582
+ Note that a combination of the second and third forms can be used where the
583
+ placeholder values are passes as an argument and not in the options object.
584
+ The ` values ` argument will override the ` values ` in the option object.
585
+
586
+ ``` js
587
+ connection .query ({
588
+ sql: ' SELECT * FROM `books` WHERE `author` = ?' ,
589
+ timeout: 40000 , // 40s
590
+ },
591
+ [' David' ],
592
+ function (error , results , fields ) {
593
+ // error will be an Error if one occurred during the query
594
+ // results will contain the results of the query
595
+ // fields will contain information about the returned results fields (if any)
596
+ }
597
+ );
598
+ ```
599
+
583
600
## Escaping query values
584
601
585
602
In order to avoid SQL Injection attacks, you should always escape any user
0 commit comments