You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MySQL2 project is a continuation of [MySQL-Native][mysql-native]. Protocol parser code was rewritten from scratch and api changed to match popular [mysqljs/mysql][node-mysql]. MySQL2 team is working together with [mysqljs/mysql][node-mysql] team to factor out shared code and move it under [mysqljs][node-mysql] organisation.
31
34
32
-
MySQL2 is mostly API compatible with [mysqljs][node-mysql] and supports majority of features. MySQL2 also offers these additional features
35
+
MySQL2 is mostly API compatible with [mysqljs][node-mysql] and supports majority of features. MySQL2 also offers these additional features:
With MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query everytime, this results in better performance. If you don't know why they are important, please check these discussions
89
+
With MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query every time, this results in better performance. If you don't know why they are important, please check these discussions:
88
90
89
91
-[How prepared statements can protect from SQL Injection attacks](http://stackoverflow.com/questions/8263371/how-can-prepared-statements-protect-from-sql-injection-attacks)
90
92
91
-
MySQL provides `execute` helper which will prepare and query the statement. You can also manually prepare / unprepare statement with `prepare` / `unprepare` methods.
93
+
MySQL2 provides `execute` helper which will prepare and query the statement. You can also manually prepare / unprepare statement with `prepare` / `unprepare` methods.
92
94
93
95
```js
94
96
// get the client
@@ -144,9 +146,9 @@ The pool does not create all connections upfront but creates them on demand unti
144
146
You can use the pool in the same way as connections (using `pool.query()` and `pool.execute()`):
145
147
```js
146
148
// For pool initialization, see above
147
-
pool.query("SELECT field FROM atable", function(err, rows, fields) {
149
+
pool.query("SELECT `field` FROM `table`", function(err, rows, fields) {
148
150
// Connection is automatically released when query resolves
149
-
})
151
+
});
150
152
```
151
153
152
154
Alternatively, there is also the possibility of manually acquiring a connection from the pool and returning it later:
If you have two columns with the same name, you might want to get results as an array rather than an object to prevent them from clashing. This is a deviation from the [Node MySQL][node-mysql] library.
229
227
230
228
For example: `select 1 as foo, 2 as foo`.
231
229
232
230
You can enable this setting at either the connection level (applies to all queries), or at the query level (applies only to that specific query).
0 commit comments