UPDATE
execute(sql, values)
execute(sql: string, values: any[])
- promise.js
- callback.js
try {
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];
const [result, fields] = await connection.execute(sql, values);
console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];
connection.execute(sql, values, (err, result, fields) => {
if (err instanceof Error) {
console.log(err);
return;
}
console.log(result);
console.log(fields);
});
-
结果:包含 ResultSetHeader 对象,该对象提供有关服务器执行的操作的详细信息。
¥result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
-
fields 包含有关操作的额外元数据(如果可用)
¥fields contains extra meta data about the operation, if available
用于查询(execute
)的连接可以通过 createConnection
、createPool
或 createPoolCluster
方法获得。
¥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 = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];
const [result, fields] = await connection.execute({
sql,
values,
// ... other options
});
console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];
connection.execute(
{
sql,
values,
// ... other options
},
(err, result, fields) => {
if (err instanceof Error) {
console.log(err);
return;
}
console.log(result);
console.log(fields);
}
);
-
结果:包含 ResultSetHeader 对象,该对象提供有关服务器执行的操作的详细信息。
¥result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
-
fields 包含有关操作的额外元数据(如果可用)
¥fields contains extra meta data about the operation, if available
用于查询(execute
)的连接可以通过 createConnection
、createPool
或 createPoolCluster
方法获得。
¥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 = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];
const [result, fields] = await connection.execute(
{
sql,
// ... other options
},
values
);
console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];
connection.execute(
{
sql,
// ... other options
},
values,
(err, result, fields) => {
if (err instanceof Error) {
console.log(err);
return;
}
console.log(result);
console.log(fields);
}
);
-
结果:包含 ResultSetHeader 对象,该对象提供有关服务器执行的操作的详细信息。
¥result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
-
fields 包含有关操作的额外元数据(如果可用)
¥fields contains extra meta data about the operation, if available
用于查询(execute
)的连接可以通过 createConnection
、createPool
或 createPoolCluster
方法获得。
¥The connection used for the query (execute
) can be obtained through the createConnection
, createPool
or createPoolCluster
methods.
词汇表
¥Glossary