我正在嘗試獲取從我的 Web 應用程式輸入的密碼,對其進行哈希處理并將其發送到我的資料庫。現在一切都在本地主機中完成。
我大部分時間都在學習教程,主要區別在于他們的資料庫是 mysql,而我使用的是 postgresql,我假設這就是我出錯的原因。
當我呼叫 db.query 時它正在崩潰。
db.query(
"INSERT INTO passwords (user_id, secure_password, iv, created_by) VALUES(?,?,?,?);",
[1058083062,hashedPassword.password, hashedPassword.iv, 1058083062],
(err,result) => {
if (err) {
console.log(err);
} else {
res.send("Success");
}
}
)
這是 db 的樣子:
const pg = require('pg');
const secret = require('./secret');
const db = new pg.Pool({
user: secret.db_user,
password: secret.db_password,
host: secret.db_host,
port: secret.db_port,
database: secret.db_database,
});
module.exports = db;
我收到此錯誤:
error: syntax error at or near ","
錯誤顯示:
{"length":90,"name":"error","severity":"ERROR","code":"42601","position":"74","file":"scan.l","line":"1180","routine":"scanner_yyerror"}
uj5u.com熱心網友回復:
嘗試
db.query(`INSERT INTO passwords (user_id, secure_password, iv, created_by) VALUES($1,$2,$3,$4)`,
[1058083062,hashedPassword.password, hashedPassword.iv, 1058083062],
(err,result) => {
if (err) {
console.log(err);
} else {
res.send("Success");
}
}
)
請注意我們改變了?,?,?,?對$1,$2,$3,$4PARAM的查詢
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/374076.html
標籤:节点.js PostgreSQL的
