我正在嘗試獲取從我的 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"}
嘗試
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,$4
PARAM的查詢
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句