Stored Procedures with Editor

Stored Procedures with Editor

Khalid TeliKhalid Teli Posts: 219Questions: 56Answers: 0

Hi Allan,

I was just having a look , can stored procedure be used in editor serverside to read data from table?

My table name is cont_test, and the stored procedure name is test . How would I tell editor to read data from Stored proceure rather than view?

 $editor  =  Editor::inst( $db, 'cont_test')
 ->readTable('test') // The VIEW to read data from

Thnak you in advance


  • allanallan Posts: 53,929Questions: 1Answers: 8,403 Site admin

    How would I tell editor to read data from Stored proceure rather than view?

    You wouldn't I'm afraid. As I noted in the thread you linked to, Editor's server-side libraries do not work with stored procedures. You could read from one by using a view to access it and instruct Editor to read from the view.


  • Khalid TeliKhalid Teli Posts: 219Questions: 56Answers: 0

    Thank you.
    I am not sure if can read a Mysql stored procedure from within View. Tried to find solution online but didn't find one.

    However, I found the solution:

    I used raw sql query as follows:

    Where $_POST["cont_prod"] is the input parameter to the stored procedure.

        if (isset($_POST["cont_prod"]) && $_POST["cont_prod"] != '')
        $abc = $_POST["cont_prod"];
           $rawquery = "CALL contract_prod($abc)";
       $data = $db->sql( $rawquery )->fetchAll();
       echo json_encode( array(
          'data' => $data
       ) );

    The client side code looks like this:
    Because, based on the stored procedure input parameter, the returned columns from database vary and that is the reason table is populate dynamically

    HTML code

    Select Contracted Product: Tomatoes Milk
    <button type="button" class="new" id="myclick" >Try it</button>
    <div class="container">
                <table id="example" class="display" width="100%">

    Js code

    <script type="text/javascript" language="javascript">
    var columns = [];
    $(document).ready(function() {
      $('').on( 'click', function () {
       var x = document.getElementById("mySelect").value;
             url: "/xxxxxxxxxxxxx/rawsql_test_fetch.php",
              data:  {cont_prod: JSON.stringify(x)},
                  success: function (data) {
            data = JSON.parse(data);
            columnNames = Object.keys([0]);
            for (var i in columnNames) {
              columns.push({data: columnNames[i], 
                        title: columnNames[i]});
          var table =    $('#example').DataTable( {
                columns: columns
            } );
    } );
    } );

    Problem1 : on selecting the values from dropdown menu , on the second draw it gives error
    DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see

    I looked at the above website, tried all solution but none is working

    **Problem2 ** : are there any drawbacks of dynamically population the table data and headers?

    Thank you

Sign In or Register to comment.