Is it possible to Fetch data from mysql ?



  • I understand the jsreport supports mssql, mongodb and postgreSQL for template stores, saving jsreport entities.

    Is it possible to just fetch data from mysql database and display in report as pdf or html based on recipe selection ?



  • Yes.
    Please take a look how to fetch data using mssql. The mysql case will be similar.
    https://jsreport.net/blog/pdf-reports-in-sql-server



  • Thanks for your quick reply as always. That worked well.

    mqsql installation;
    npm install mysql

    code:

    var mysql = require('mysql');
    
    var con = mysql.createConnection({
        host: "server-name",
        user: "user-name",
        password: "password",
        database: "sample",
        port: "3306",
    });
    
    function beforeRender(request, response, done) {
        con.connect(function(err) {
            if (err) throw err;
            con.query('select name,value from tblparameter', function(err, result, fields) {
                if (err) throw err;
                request.data = {
                    config: result
                };
                done();
            });
        });
    }
    


  • Thanks for sharing the code.



  • That was very helpful! Thank you!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.