I have a Stored Procedure (SP from now on) that inserts data to the database (SaveClient, see below). When the SP is done I redirect the PHP page to a different PHP page that lists the entries (FetchObjectList, see below). The list does not return the newly created record until I then reload/refresh the page.
The stored procedure has a COMMIT at the end, I close the database connection in the PHP code after the SP is called and there is a check for errors but nothing goes wrong.
The page itself returns a 200 statuscode which means it isn't cached so can't be browserrelated either.
The current workaround is a sleep(1) in the PHP code but when the code goes live I have no idea if it will suffice. I'd ofcourse rather have MySQL dish out the correct resultset.
EDIT: I'm using the MySQLi object interface of PHP, might be useful to know. ;)
My devcomputer got PHP 5.2.17, MySQL 5.0.51a (InnoDB) and Apache 2.2.17 installed and running on Windows 7 x64.
UPDATE
Added the following line CALL FetchObjectList('client_tbl', NULL, NULL, 1, 'client_tbl.name ASC', NULL, NULL); to the end of SaveClient. The resultset does not have the newly created client in the presented resultset.
UPDATE 2
I tried using the SQL_NO_CACHE as seen here but to no avail.
I will now try the same SQL directly in PHP instead of calling the SPs.
UPDATE 3 - 20 september
I've tried any reasonable answer/comment I've got so far without any luck. I tried to update my PHP and MySQL version today (since I today learned that the live server will run on PHP 5.3.something and MySQL 5.1.something) but did not get it to work. I need to update the PHP to get a more recent php_mysqli.dll/libmysql.dll since the one I got has only supports up to 5.0.51a and there might be my problem since nothing in the actual DB has worked. I tried the libmysql.dll from the MySQL install to no avail.
Note that I also changed the PHP code that I've included since I actually copied the wrong one that was calling the user_tbl and not the client_tbl and also simplified it (removed multiqueries) but still the same result.
I don't know what will happen to the bounty, if it reverts back to me I'll add it again.
Stored Procedure SaveClient
DELIMITER //
DROP PROCEDURE IF EXISTS work.SaveClient//
CREATE PROCEDURE work.SaveClient(
IN ObjectID INT,
IN UserID INT,
IN ClientName VARCHAR(60),
IN VersionFrom DATETIME,
IN VersionTo DATETIME)
root:BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
/*
Default values ---------------------------------------------------------------------------------------------------------
*/
# Used to block INSERT/UPDATEs
SET #DoChanges = TRUE;
SET #Fields = '*';
SET #Version = NULL;
SET #UserVersion = NULL;
SET #DateNow = NOW();
SET #VersionActive = CONCAT(
'( ( NOW() BETWEEN ',
'version_from AND ',
'version_to ) OR ( ',
'version_from < NOW() AND ',
'version_to IS NULL ) )'
);
IF VersionFrom IS NULL THEN
SET VersionFrom = #DateNow;
END IF;
/*
Search for client ------------------------------------------------------------------------------------------------------
*/
IF ObjectID IS NOT NULL THEN
SET #Client = CONCAT(
'SELECT version INTO #Version FROM client_tbl WHERE object_id = ',
ObjectID,
' AND ',
#VersionActive
);
PREPARE stmt FROM #Client;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
# Check if there are any changes
IF #Version IS NOT NULL THEN
SELECT name INTO #Name FROM client_tbl WHERE name = ClientName AND version = #Version;
IF #Name = ClientName THEN
SET #errorMsg = "Duplicate entry";
SET #errorCode = "S0000002";
SELECT #errorCode, #errorMsg;
LEAVE root;
END IF;
END IF;
END IF;
/*
Search for user ---------------------------------------------------------------------------------------------------------
*/
# Create this as a function
IF UserID IS NOT NULL THEN
SET #User = CONCAT(
'SELECT version INTO #UserVersion FROM user_tbl WHERE object_id = ',
UserID,
' AND ',
#VersionActive
);
PREPARE stmt FROM #User;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
IF #UserVersion IS NULL THEN
SET #errorMsg = "User is missing";
SET #errorCode = "U0000099";
SELECT #errorCode, #errorMsg;
LEAVE root;
END IF;
/*
Add the client ---------------------------------------------------------------------------------------------------------
*/
# Close the current version
IF #Version IS NOT NULL THEN
IF #DoChanges = TRUE THEN
CALL UpdateVersion(
ObjectID,
UserID,
#Version,
#DateNow,
'client_tbl'
);
SET #Version = #Version + 1;
END IF;
ELSE
SET #Version = 1;
END IF;
IF #DoChanges = TRUE THEN
IF ObjectID IS NULL THEN
INSERT INTO
object_tbl
(
object_class_id,
created,
created_by
)
VALUES(
2,
NOW(),
UserID
)
;
SET ObjectID = LAST_INSERT_ID();
END IF;
INSERT INTO
client_tbl
(
object_id,
version,
version_from,
version_to,
changed,
changed_by,
name
)
VALUES(
ObjectID,
#Version,
VersionFrom,
NULL,
#DateNow,
UserID,
ClientName
)
;
END IF;
COMMIT;
END //
DELIMITER ;
Stored Procedure FetchObjectList
DELIMITER //
DROP PROCEDURE IF EXISTS work.FetchObjectList//
CREATE PROCEDURE work.FetchObjectList(
IN ObjectType VARCHAR(60),
IN ObjectSubType VARCHAR(60),
IN ObjectSubID INT,
IN IsActive INT,
IN OrderBy VARCHAR(100),
IN SetStart INT,
IN MaxResults INT)
root:BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
# Allow the "JSON" output be a max of 8kb
SET GLOBAL group_concat_max_len = 8096;
/*
Default values ---------------------------------------------------------------------------------------------------------
*/
SET #Fields = '*';
SET #VersionWhere = '1'; # Get everything
SET #Special = '';
SET #OrderBy = '';
SET #SetStart = '';
SET #MaxResults = '';
SET #JoinIn = '';
IF IsActive = 1 THEN
SET #VersionWhere = CONCAT(
'( NOW() BETWEEN ',
ObjectType,
'.version_from AND ',
ObjectType,
'.version_to OR ( ',
ObjectType,
'.version_from < NOW() AND ',
ObjectType,
'.version_to IS NULL ) )'
);
END IF;
IF OrderBy != '' THEN
SET #OrderBy = CONCAT(
'ORDER BY ',
OrderBy
);
END IF;
/*
Specials for each type -------------------------------------------------------------------------------------------------
*/
/*
- Clients ------------
*/
IF ObjectType = 'client_tbl' THEN
SET #Fields = '
*,
client_tbl.object_id AS object_id,
(
SELECT
COUNT(*) AS Total
FROM
client_user_privilege_tbl cup
WHERE
cup.client_id = client_tbl.object_id
) AS usercount
';
END IF;
/*
- Configuration ------------
*/
IF ObjectType = 'configuration_tbl' THEN
SET #Fields = '
*
';
END IF;
/*
Add upp the query to run -----------------------------------------------------------------------------------------------
*/
SET #Query = CONCAT(
'SELECT ',
#Fields,
' FROM ',
ObjectType,
' ',
#JoinIn,
' WHERE ',
#VersionWhere,
' ',
#Special,
#OrderBy
);
PREPARE stmt FROM #Query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
COMMIT;
END //
DELIMITER ;
PHP CODE SNIPPET (Updated 20 september)
$query = "CALL FetchObjectList('client_tbl', NULL, NULL, 1, NULL, NULL, NULL)";
addTrace($query);
$rs = $db->query($query);
if( $rs ) {
addTrace('Query done -> Results: ' . $rs->num_rows);
while($r = $rs->fetch_assoc()){
$fetchArray[] = $r;
}
$count = $rs->num_rows;
$rs->close();
$db->next_result();
} else {
addTrace('Query failed -> ' . $db->error);
flushTrace();
exit;
}
Since it's a pretty aged version of mysql it would not surprise me that this would be bug related but one thing I would -in your place- want to know is if this would work by not using transactions at all. (e.g. autocommit = on).
For that version 5.0 I would also check the query cache and disable it all together instead of per query (see SHOW VARIABLES LIKE 'have_query_cache'; SET GLOBAL query_cache_size =0; ). That would at the least eliminate those playing a role in this problem, reproduce(or try) the problem and see if anything changed. If not, I would start searching for specific bugs, especially when the query cache is disabled and it still does this without using transactions.
I verified the support for 5.0 mysql (innodb).
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
Set these options specifically in your my.cnf, the top one is most important. They explain nicely what those do.
See http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html#sysvar_innodb_flush_log_at_trx_commit
The problem with mysql_query is that it does not support multiple resultsets. And that is exactly what your stored procedures do – they tend to return more than one resultset. Whenever you call an SP, the exit status is secretly carried in an (empty) resultset along. If you add it up with your own output from a procedure, some of the resultsets from the query will be ignored by your PHP retrieval code. When you try to run another query, the pending resultset(s) will still be in the buffer.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
I tried to generate an auto increment value but MySQL does not implement it.
There are many things to solve the problem. Let me show you one of them by using MySQL procedures.
Steps are as follows:
1°) create a procedure that generates an identifier for a table (generate_id)
2°) create a procedure that inserts the data into the table (insert_users) by using the first procedure (generate_id) to get a formatted ID, then it will return the inserted ID as a SELECT query.
3°) Now, call the inserting procedure (insert_users)
For more information, chat with Michel Magloire Ekanga who is the main creator of this craftiness.
LET'S USE AN EXAMPLE FOR EACH STEP
STEP 1
generate_id procedure that should take as parameters: table_name, the primary_key, a joiner or a prefix for ID, the length for ID, and the output
Our result should be as below: USER20210909000002 (joiner=USER, year=2021, mounth=09, day=09, increment=000002)
# --------------------- DEFINITION ------------------------------
DROP PROCEDURE IF EXISTS generate_id;
DELIMITER $$
CREATE PROCEDURE generate_id(IN _db_table VARCHAR(255), IN _pkey VARCHAR(255),IN _joiner VARCHAR(255),_length INT, OUT _new_id VARCHAR(255))
BEGIN
SET #max_id = NULL;
SET #sql = CONCAT('select max(`', _pkey, '`) into #max_id from `', _db_table, '`');
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
#------- Length for identifier -------
SET #length = 10;
SET #joiner_len = CHAR_LENGTH(_joiner);
IF _length > 0 AND (_length - CHAR_LENGTH(_joiner)) >= 10 THEN
SET #length = _length;
END IF;
#----------------------------
#--- the date variables ---
SET #today = DATE_FORMAT(NOW(),'%Y%m%d');
SET #r_str = LPAD(1,(#length - (8 + #joiner_len)), '0');
#
#---- FORMATING ID ------------------------
#
IF #max_id IS NULL THEN
# the table is empty
SET _new_id = CONCAT(_joiner,#today,#r_str);
ELSE
# the table is not empty
# 1°) reading parts from previous ID
SET #strlen = CHAR_LENGTH(#max_id);
SET #old_r_str = SUBSTR(#max_id, (#joiner_len + 4 + 2 + 2 + 1), #strlen);
SET #old_idx = CONVERT(#old_r_str, SIGNED INTEGER);
# 2°) checking if dates are the same
SET #old_date = SUBSTR(#max_id, (#joiner_len + 1), 8);
-- dates are not the same, we just take the 8 characters for date from the field
SET #new_idx = 1;
SET #new_r_str = LPAD(#new_idx,(#length - (8 + #joiner_len)), '0');
SET #new_max = CONCAT(_joiner,#today,#new_r_str);
IF #today = #old_date THEN
SET #new_idx = #old_idx + 1;
SET #new_r_str = LPAD(#new_idx,(#length - (8 + #joiner_len)), '0');
SET #new_max = CONCAT(_joiner,#old_date,#new_r_str);
END IF;
SET _new_id = #new_max;
END IF;
END;
$$
DELIMITER ;
STEP 2
Procedure that uses the generated ID for insertion, we don't need to provide an ID, it will generate the ID automaticaly
DROP PROCEDURE IF EXISTS insert_users;
DELIMITER $$
CREATE PROCEDURE insert_users(
login_user VARCHAR(255),
pass_user VARCHAR(255)
)
BEGIN
CALL generate_id('users', 'row_id', 'USR', 22, #new_id);
SET #last_inserted_id = #new_id;
SET #sql = CONCAT("INSERT INTO users(row_id, login_user, pass_user) VALUES ('",
#last_inserted_id, "','",
login_user, "','",
pass_user, "')"
);
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
# ---- export the new ID before exiting the function
SELECT #last_inserted_id AS lastInsertId;
END;
$$
DELIMITER ;
STEP 3
How to use with PHP, for example
<?php
function insert(){
$db = $pdo; // I am using PDO as driver, renewed as Class
$lastInsert = null;
//---------------
$sql = "CALL insert_users(?,?)";
//---------------
$req = $db->prepare($sql);
$req->execute($login_user,$pass_user);
if($req->rowCount() > 0){
$lastInsert = $req->fetch()->lastInsertId;
return true;
}else{
return false;
}
}
?>
I have configured this procedure:
DELIMITER //
CREATE PROCEDURE get_news
(IN news_id INT)
BEGIN
SELECT title, body, datetime FROM News
WHERE id = news_id;
END //
DELIMITER ;
And I have this PHP Code:
$news_id = $_GET["id"];
$dbConnection = new mysqli("localhost","root","","identidad_digital_db");
$sql = "CALL get_news($news_id)";
$result = $dbConnection->query($sql);
$count = $result->num_rows;
if($count==0){
header( 'Location: id_not_found.html' );
}
$m = $result->fetch_assoc()
I thought that my procedure will fix SQL Injection. However, vulnerability still working. "id" must be only an integer. By this way, the basic "7' and '1'='2" injection works.
Why it does not works? How can I configure correctly my procedure? I read the documentation and some examples but I don't know how to do it.
UPDATE
I'am triying with regex but It also does not works:
BEGIN
IF news_id IS NOT NULL AND news_id RLIKE '^[0-9]+$'
THEN
SELECT title, body, datetime FROM News
WHERE id = news_id;
END IF;
END //
You can use CAST for this:
IF CAST(news_id AS UNSIGNED) > 0 THEN
...
END IF;
However, I think you should do this in php:
if(isset($news_id) && is_numeric($news_id)){
...
}
SOLVED!
I configure news_id as varchar(20). Obviously, in my mind these values were int types but they come from a PHP form, so they are strings. By the way, if it helps someone, this is what I got finally:
DELIMITER //
DROP PROCEDURE IF EXISTS get_news //
CREATE PROCEDURE get_news
(IN news_id VARCHAR(20))
BEGIN
IF news_id IS NOT NULL AND news_id REGEXP '^[1-9]+$' THEN
SELECT id, title, body, datetime FROM News
WHERE id = news_id;
END IF;
END //
DELIMITER ;
I'm stumped. I want to store either a serialize()'d or json_encode()'d array in MySQL using a stored procedure. This would be to store a user's checked boxes or multiselect options.
We are using stored procedures, and while I like to think I've gotten a good grip on them over the last few months, I'm not sure how to solve the following error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'One","Three","Two"]")' at line 1 (SQL: CALL CategoryFieldValues_UpdateAttributeByID("3077", "1", "1234", "field_value", "["One","Three","Two"]"))
Here is my stored procedure:
CREATE PROCEDURE `CategoryFieldValues_UpdateAttributeByID`(
IN siteID INT UNSIGNED,
IN ID INT UNSIGNED,
IN modifiedByID INT UNSIGNED,
IN attribute VARCHAR(255),
IN attrValue VARCHAR(255)
)
BEGIN
SET #d = IHaveAFunctionHere( siteID );
SET #n = 'null';
IF attribute = "category_field_id" THEN SET #n = 0; END IF;
SET #s = CONCAT(
'UPDATE ', #d,'.category_field_values cfv
SET
', attribute, ' = ', QUOTE(NULLIF(attrValue, #n)), ',
modified_by = ', QUOTE(modifiedByID), '
WHERE cfv.id = ', ID, ';' );
PREPARE statement FROM #s;
EXECUTE statement;
SELECT ROW_COUNT() AS ROW_COUNT;
DEALLOCATE PREPARE statement;
END$$
This procedure takes information like the siteID, which it uses to find the right database, and an attrValue that is the value I want to set. It works fine, but now when I need to drop a json_encoded or serialized array at it, it chokes.
The json_encoded array ends up looking like ["One","Three","Two"].
I'm guessing it's bugging out because of unescaped quotes or square brackets, but I'm not totally sure.
Also, I tried a slightly different syntax (below) to no avail:
BEGIN
SET #d = IHaveAFunctionHere( siteID );
SET #n = 'null';
SET #attrValue = attrValue;
IF attribute = "category_field_id" THEN SET #n = 0; END IF;
SET #s = CONCAT(
'UPDATE ', #d,'.category_field_values cfv
SET
', attribute, ' = ?,
modified_by = ', QUOTE(modifiedByID), '
WHERE cfv.id = ', ID, ';' );
PREPARE statement FROM #s;
EXECUTE statement USING #attrValue;
SELECT ROW_COUNT() AS ROW_COUNT;
DEALLOCATE PREPARE statement;
END
I've also tried removing the QUOTEs, and some other small tweaks, and I'm just spent.
I've written this code for mysql pivot table:
SET #SQL = NULL;
SET ##group_concat_max_len = 6000;
SELECT GROUP_CONCAT( DISTINCT CONCAT( 'MAX(IF(questiondetails = \'', questiondetails, '\', answer, null)) AS \'', questiondetails, '\' ' )) INTO #SQL FROM wtfeedback;
SET #SQL = CONCAT( 'SELECT trialid, productsku, userkey, category, ', #SQL, ' FROM wtfeedback GROUP BY trialid' );
PREPARE stmt FROM #SQL;
EXECUTE stmt;
This works fine in Sequel Pro (mysql gui editor)
But when I paste into my php page to run this code it is showing a syntax error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET ##group_concat_max_len = 6000;
SELECT GROUP_CONCAT( DISTINCT CONCAT( 'MAX(I' at line 3
I'm struggling to see what the error might be.
Any ideas ? Thanks in advance.
MySQL doesn't use '' to escape single quotes. If you want to embed single quotes in your in-sql strings, then use \':
CONCAT('MAX(IF(questiondetails = \'', questiondetails, '\', answer, null)) AS "', questiondetails, '" ')
^^---------------------^^
From PHP, issue only one statement at a time. I deduce that this is the problem since the error is pointing at the beginning of the second SET.
Here is a stored proc to generate a pivot SELECT for you.
I was struggling with the same issue as Guy Murray, but fought my way out.
Basically I made a stored procedure that lets you run a pivot table on selectable rows and columns, with optional filtering. It does so by first storing the result of a "group by" select query in a temp table, and then fiddling that to a pivot table with the "group_concat" function. Same trick as Guy does.
The advantage is that it goes through the main table only once, which may save time if there are zillions of records in it.
Here is a sample table:
CREATE TABLE `Data` (
`Period` INT(2) NOT NULL,
`Product` VARCHAR(20) NOT NULL DEFAULT '',
`Amount` DOUBLE NOT NULL
) ENGINE=INNODB DEFAULT CHARSET=latin1;
INSERT INTO `Data` (`Period`, `Product`, `Amount`)
VALUES
(1,'PrdA',15484),
(1,'PrdA',45454),
(1,'PrdB',478),
(2,'PrdB',985),
(2,'PrdB',741),
(2,'PrdB',985),
(3,'PrdA',7515),
(3,'PrdA',454),
(3,'PrdB',4584),
(2,'PrdB',445),
(1,'PrdB',669);
And this is the stored procedure. Additional comment in the code.
DELIMITER ;;
CREATE DEFINER=`root`#`localhost` PROCEDURE `pivot`(
source VARCHAR(1000),
val VARCHAR(40),
rws VARCHAR(40),
cls VARCHAR(40),
filter VARCHAR(1000))
BEGIN
/*
Creates a pivot table from any table, view or SQL statement.
Mandatory: source, value, rows, and columns to be pivoted.
Optional filtering.
Sample call strings:
CALL pivot('data', 'amount', 'period', 'product', '');
CALL pivot('(select * from data)', 'amount', 'product', 'period', 'WHERE amount>1000');
*/
/*just to be sure*/
DROP TEMPORARY TABLE IF EXISTS temp1;
/*increase the value of group concat, otherwise the number of columns is very limited*/
SET SESSION group_concat_max_len = 100000;
/*perform a "select...group by" on the source and store it in a temp table1*/
SET #a=CONCAT(
'CREATE TEMPORARY TABLE temp1 (
SELECT ',
rws,' AS rows, ',
cls,' AS cols,
SUM(',val,') AS val
FROM ',source,' S ',
filter, '
GROUP BY '
,rws,', ',
cls,');'
);
PREPARE stmt FROM #a;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
/*use "distinct columns" from temp1 to make a text string #coltext, that contains the column statements, to be used in the final step
Produced text string looks like this: sum(CASE WHEN cols='PrdA' THEN val END) AS 'PrdA', sum(CASE WHEN cols='PrdB' THEN val END) AS 'PrdB' */
SELECT GROUP_CONCAT(
' SUM(CASE WHEN cols=\'',cols,'\' THEN val END) AS \'',cols,'\'')
INTO #coltext
FROM (SELECT DISTINCT(cols) AS cols FROM temp1) A;
/*build the final statement in #b*/
SET #b=CONCAT(
'SELECT
IFNULL(rows, \'Total\') AS ',rws,', '
,#coltext,',
SUM(val) AS Total
FROM temp1
GROUP BY
rows
WITH ROLLUP;');
/*and launch it*/
PREPARE stmt FROM #b;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
/*clean up*/
DROP TEMPORARY TABLE IF EXISTS temp1;
SET #a=NULL;
SET #b=NULL;
SET #coltext=NULL;
END;;
DELIMITER ;
The result looks like this:
period PrdA PrdB total
1 60938 1147 62085
2 NULL 3156 3156
3 7969 4584 12553
total 68907 8887 77794
Hope this shows up correctly on stack overflow. It's my first post here.
edit 2015-10-19: when reading others solutions here, I realised that the code could be cleaned up and improved: it's now free of any hardcoded references. Just plug it in any database and it will work.
I am trying to run a procedure in which i will send the table name to fetch all records from it..so that i don't have to create different procedure...but i am facing some problem in that.
ALTER PROCEDURE [dbo].[getTableData]
-- Add the parameters for the stored procedure here
#tableName Varchar(100),
#whrFldName NVarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE #ActualTableName AS NVarchar(255)
SELECT #ActualTableName = QUOTENAME( TABLE_NAME )
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = #tableName
DECLARE #sql AS NVARCHAR(MAX)
SELECT #sql = 'SELECT * FROM ' + #ActualTableName + ' WHERE ' +
#whrFldName + ' = ''y'' ;'
--PRINT #sql
EXEC(#SQL)
END
The PHP code is this..
$sql ="EXEC [dbo].[getTableData] 'tbl_services','serviceStatus'";
$rst = odbc_exec($connection, $sql);
$i = 0;
while($result = odbc_fetch_array($rst))
{
$returnPageData[$i] = $result;
$i++;
}
It executes just fine in server but when I call it from my PHP code, it returns null.
Here if I remove * and place fields it works fine..I have tested my code well,it specially creates the problem for a Text type field..
If i change the procedure to this,it works fine..
ALTER PROCEDURE [dbo].[getTableData]
-- Add the parameters for the stored procedure here
#rowsPerPage as bigint,
#pageNum as bigint
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
WITH SQLPaging AS (
SELECT TOP(#rowsPerPage * #pageNum) ROW_NUMBER() OVER (ORDER BY creationDate DESC)
AS resultNum, *
FROM [DB_SB].[dbo].[tbl_blog] )
SELECT
blogTitle,
blogSlug,
blogImage,
substring( blogContent, 1, 210 ) AS blogContent,
creationDate,
blogAddedBy
FROM SQLPaging WITH (nolock) WHERE resultNum > ((#pageNum - 1) * #rowsPerPage)
END
But this is no logical..if i send fields everytime..this is not what i want exactly..
Any solution??please help...
You need to use SQL Server Profiler to see what’s actually getting to database engine.
If your stored procedure is executed correctly when run from SSMS then there is a problem somewhere in PHP part.
Are you using the same database using when testing from SSMS? There might be some issue in that…