0

I am trying to implement a filter in jTable. Here is the jTable Filtering Demo.

I used the jQuery code supplied by the demo to sucessfully send POST data to the listAction php script. I access this data and assign it to the $filter variable. I also add two wildcards before and after the string to tell MySQL to perform a comprehensive search rather then an index search.

    $filter = '%';
    $filter .= $_POST['name'];
    $filter .= '%';
    $startIndex = $_GET['jtStartIndex'];
    $pageSize = $_GET['jtPageSize'];
    $sorting = $_GET['jtSorting'];

I then call the stored procedure and pass in each variable. I removed actual database and procedure name, but I verified they are correct.

$mysqli->query("USE data;");
$res = $mysqli->query("CALL proced($startIndex, $pageSize, $filter);");

$res returns false here.

Calling Stored Procedures DEFINITELY works as I have other functionalities working this way. I have other Stored Procedures working that simply return 0 to 9 records correctly. Here is the current Stored Procedure code:

CREATE DEFINER=`root`@`localhost` PROCEDURE `proced`(startIndex INTEGER, pageSize INTEGER, filter VARCHAR(255))
BEGIN
    SELECT * FROM reports 
    WHERE `new`=0 AND ReportingName LIKE filter
    ORDER BY idReports ASC 
    LIMIT startIndex, pageSize;
END

Passing in values in MySQL workbench works and the query returns the correct rows:

call proced(
    0,
    10,
    'Art%'
);

But jTable fails with "An error occured while communicating to the server."

Can anyone point me in the right direction?

andrsnn
  • 1,591
  • 5
  • 25
  • 43

1 Answers1

0

Got this working by getting an error back from MySQL:

if(!$res){
    ChromePhp::log($mysqli->error);
    die('error ['. $mysqli->error . ']');

}

Error:

Unknown column 'Art' in 'field list'

Solution(copied from link):

Try using different quotes for "Art" as the identifier quote character is the backtick (“`”). Otherwise MySQL "thinks" that you point to a column named "Art".

See also MySQL 5 Documentation

So simply by adding single quotes to the passed in String parameter works:

CALL procedure('$filter');
Community
  • 1
  • 1
andrsnn
  • 1,591
  • 5
  • 25
  • 43