SELECT
execute(sql, values)​
execute(sql: string, values: any[])
- promise.js
- callback.js
try {
const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';
const values = ['Page', 45];
const [rows, fields] = await connection.execute(sql, values);
console.log(rows);
console.log(fields);
} catch (err) {
console.log(err);
}
const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';
const values = ['Page', 45];
connection.execute(sql, values, (err, rows, fields) => {
if (err instanceof Error) {
console.log(err);
return;
}
console.log(rows);
console.log(fields);
});
- rows contains rows returned by server
- fields contains extra meta data about rows, if available
info
The connection used for the query (execute
) can be obtained through the createConnection
, createPool
or createPoolCluster
methods.
execute(options)​
execute(options: QueryOptions)
- promise.js
- callback.js
try {
const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';
const values = ['Page', 45];
const [rows, fields] = await connection.execute({
sql,
values,
// ... other options
});
console.log(rows);
console.log(fields);
} catch (err) {
console.log(err);
}
const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';
const values = ['Page', 45];
connection.execute(
{
sql,
values,
// ... other options
},
(err, rows, fields) => {
if (err instanceof Error) {
console.log(err);
return;
}
console.log(rows);
console.log(fields);
}
);
- rows contains rows returned by server
- fields contains extra meta data about rows, if available
info
The connection used for the query (execute
) can be obtained through the createConnection
, createPool
or createPoolCluster
methods.
execute(options, values)​
execute(options: QueryOptions, values: any[])
- promise.js
- callback.js
try {
const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';
const values = ['Page', 45];
const [rows, fields] = await connection.execute(
{
sql,
// ... other options
},
values
);
console.log(rows);
console.log(fields);
} catch (err) {
console.log(err);
}
const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';
const values = ['Page', 45];
connection.execute(
{
sql,
// ... other options
},
values,
(err, rows, fields) => {
if (err instanceof Error) {
console.log(err);
return;
}
console.log(rows);
console.log(fields);
}
);
- rows contains rows returned by server
- fields contains extra meta data about rows, if available
info
The connection used for the query (execute
) can be obtained through the createConnection
, createPool
or createPoolCluster
methods.