Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

node.js - nodejs postgresql send secure parameters error

I want to send parameters securly with postgresql to prevent sql injections.

if I send the parameter I will get this error Message: There is no Parameter $1

what do I am wrong?

'use strict';

const { Pool } = require('pg');

const pool = new Pool({
    user: 'postgres',
    host: '127.0.0.1',
    database: 'TEST',
    password: 'xxxx',
    port: 4551,
});

const Query = async query => {
    try {
        await pool.connect();

        const res = await pool.query('SELECT email FROM client WHERE email = $1', ["[email protected]"]);
        console.log(res.rows[0]);
        await pool.end();
    } catch(e) {
        return e;
    }
};

module.exports = Query;

€: And should I use client or pool ?

question from:https://stackoverflow.com/questions/65650614/nodejs-postgresql-send-secure-parameters-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...