jTable jQuery plugin why is my MySQL stored procedure failing?

為{幸葍}努か 提交于 2019-12-25 00:38:13

问题


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?


回答1:


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');


来源:https://stackoverflow.com/questions/24293054/jtable-jquery-plugin-why-is-my-mysql-stored-procedure-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!