跳到主要内容

SELECT

execute(sql, values)

execute(sql: string, values: any[])

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);
}
  • rows contains rows returned by server
  • fields contains extra meta data about rows, if available
信息

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


execute(options)

execute(options: QueryOptions)

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);
}
  • rows contains rows returned by server
  • fields contains extra meta data about rows, if available
信息

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[])

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);
}
  • rows contains rows returned by server
  • fields contains extra meta data about rows, if available
信息

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


Glossary

QueryOptions

QueryOptions Specification