2

I have a Stored Procedure that works fine in MySQL returning a single value.

However when trying to call it with PHP it returns the correct values but also returns the below three errors

Warning: PDOStatement::execute(): Premature end of data (mysqlnd_wireprotocol
Warning: PDOStatement::execute(): RSET_HEADER packet 1 bytes shorter than expected 
Warning: PDOStatement::execute(): Error reading result set's header 

They all refer to line 90 where I'm executing the SP via a PDO parameterised query

$Statement->execute();

Does anyone know why I get these errors? googling around mostly refers to getting this when being denied access to the DB with an "old" style password. I don't have this problem as the SP is working returning the correct values but with the three error messages.

Hi Markus,Thanks for responding. Sorry I've been away. My PHP version is 5.5.12 and MySQL Version is 5.6.17 I'm using the latest WampServer on my box. The error messages do not mention "using old password" Currently I get the SP to work fine using the below code but I have to return the SP result as a VARCHAR and then convert the "true/false" string to bool with PHP. If I try returning the SP values as an INT this is when I get the errors...

stored procedure:

CREATE DEFINER=`MyDB`@`localhost` PROCEDURE `new_account`(
IN Cus_Title VARCHAR(4),
IN Cus_Name VARCHAR(35),
IN Cus_Surname VARCHAR(35),
IN Cus_Email VARCHAR(75),
IN Cus_Password VARBINARY(255),
IN Cus_Status TINYINT(1),
IN Cus_LoginIP VARCHAR(45),
IN Cus_Created TIMESTAMP,

IN Pho_Number VARCHAR(14),

IN Com_Name VARCHAR(50),
IN Com_BuildingNumber VARCHAR(14),
IN Com_Address VARCHAR(100),
IN Com_Street VARCHAR(35),
IN Com_City VARCHAR(25),
IN Com_County VARCHAR(35),
IN Com_PostCode VARCHAR(12),

IN Act_ActivationToken VARBINARY(255),
IN Act_Expiry TIMESTAMP,
-- OUT ReturnStatus INT(3) using this I get errors from PHP
OUT ReturnStatus VARCHAR(5)
)
BEGIN
DECLARE Cus_ID INT(11) UNSIGNED; -- CustomerID
DECLARE Com_ID INT(11) UNSIGNED; -- CompanyID

IF EXISTS(SELECT Email FROM customers WHERE Email = Cus_Email) THEN
SET ReturnStatus = "false";
SELECT ReturnStatus;
ELSE
INSERT INTO customers(Title, Name, Surname, Email, Password, Status, LoginIP, Created)
VALUES(Cus_Title, Cus_Name, Cus_Surname, Cus_Email, Cus_Password, Cus_Status, Cus_LoginIP, Cus_Created);
SET Cus_ID = LAST_INSERT_ID();


IF(Pho_Number != '') THEN -- Customer has registered a mobile number
INSERT INTO customers_phones(CustomerID, Type, Number)
VALUES(Cus_ID, 'Mobile', Pho_Number);
END IF;

IF EXISTS(SELECT ID, Name, PostCode FROM companys WHERE Name = Com_Name AND PostCode = Com_PostCode) THEN
SET Com_ID = (SELECT ID FROM companys WHERE Name = Com_Name AND PostCode = Com_PostCode);
ELSE
INSERT INTO companys(Name, BuildingNumber, Address, Street, City, County, PostCode)
VALUES(Com_Name, Com_BuildingNumber, Com_Address, Com_Street, Com_City, Com_County, Com_PostCode);
SET Com_ID = LAST_INSERT_ID();
END IF;

INSERT INTO customers_order_delivery(CustomerID, CompanyID)
VALUES(Cus_ID, Com_ID);

INSERT INTO customers_activations(CustomerID, ActivationToken, Expiry)
VALUES(Cus_ID, Act_ActivationToken, Act_Expiry);

INSERT INTO customers_subscriptions(CustomerID, Type, Method)
VALUES(Cus_ID, 'Newsletter', 'Email');
SET ReturnStatus = 'true';
SELECT ReturnStatus;
END IF;
END;


PHP bindings are as follows and are contained within a try/catch block:

$SQL = 'call new_account(:Cus_Title, :Cus_Name, :Cus_Surname, :Cus_Email, :Cus_Password, :Cus_Status, :Cus_LoginIP, :Cus_Created, :Pho_Mobile, :Com_Name, :Com_BuildingNumber, :Com_Address, :Com_Street, :Com_County, :Com_City, :Com_PostCode, :Act_ActivationToken, :Act_Expiry, :ReturnStatus)';
$Statement = $Connection->prepare($SQL);
#Bind parameters
$Statement->bindParam(':Cus_Title', $_Form->Validated['Title']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Cus_Name', $_Form->Validated['Name']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Cus_Surname', $_Form->Validated['Surname']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Cus_Email', $_Form->Validated['Email']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Cus_Password', $_Form->Validated['Password']['input'], PDO::PARAM_LOB);
$Statement->bindParam(':Cus_Status', $_Form->Validated['UserStatus']['input'], PDO::PARAM_INT);
$Statement->bindParam(':Cus_LoginIP', $_Form->Validated['LoginIP']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Cus_Created', $_Form->Validated['CreatedOn']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Pho_Mobile', $_Form->Validated['Mobile']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Act_ActivationToken', $_Form->Validated['ActivationToken']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Act_Expiry', $_Form->Validated['Expiry']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_Name', $_Form->Validated['Company']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_BuildingNumber', $_Form->Validated['BuildingNumber']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_Address', $_Form->Validated['Address']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_Street', $_Form->Validated['Street']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_City', $_Form->Validated['City']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_County', $_Form->Validated['County']['input'], PDO::PARAM_STR);
$Statement->bindParam(':Com_PostCode', $_Form->Validated['PostCode']['input'], PDO::PARAM_STR);
$Statement->bindParam(':ReturnStatus', $ReturnStatus, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, 3);
$Statement->execute();
$AccountCreationStatus = $Statement->fetchColumn();  //Check the account was successfully created


$AccountCreationStatus = ($AccountCreationStatus == 'true') ? true : false; // Convert return from SP as currently its buggy as cannot return INT or BOOL
if($AccountCreationStatus){ // New account was successfully created
#Send new user activation email

Hi R3uK, EdChum, Wtower, Rajesh, and pinkal My post is not a duplicate because in the solution referenced In that instance they talk about not being able to connect to MySQL. If you all read my post a little more carefully you would see that I can connect to MySQL fine as evidenced by my SP and script being able to run. Returning the correct values as a string. however if I try and get the return as an int of 1 or 0 I still get the correct return output from the SP but with the addition of 3 php error messages following immediately after the output and they mention nothing about "old authentication. To avoid confusion and for clarity the error messages in full are:

    • ( ! ) Warning: Unknown: Premature end of data (mysqlnd_wireprotocol.c:1116) in Unknown on line 0
    • ( ! ) Warning: Unknown: RSET_HEADER packet 1 bytes shorter than expected in Unknown on line 0
    • ( ! ) Warning: Unknown: Error reading result set's header in Unknown on line 0

Also before I posted I did spend a considerable amount of time searching for possible solutions and did see that post and checked my passwords in MySQL and it's using the new authentication... unless I'm missing something. Please be a little more careful next time before dismissing a post as a duplicate as it's clear from my post that it's not.

That said any help would very much be appreciated. PHP Addict

PHP Addict
  • 71
  • 1
  • 9

1 Answers1

0

I guess you just skipped some information in your post so the complete error message sounds like this one:

...: Premature end of data (mysqlnd_wireprotocol.c:554) in ...
...: OK packet 1 bytes shorter than expected in ...
...: mysqlnd cannot connect to MySQL XXX using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP XXX or earlier you might need to remove the old-passwords flag from your my.cnf file in ... 

If so you can easily solve your problem by following the information in the error text. You can find more details here.

Community
  • 1
  • 1
Markus Safar
  • 6,324
  • 5
  • 28
  • 44