/    Sign up×
Community /Pin to ProfileBookmark

Help with SQLSTATE[HY000] Please

Hi,

Why I am getting:

[code=php]Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000]: General error’ in /home/meskholdings/mybluefile.com/change_password.php:22 Stack trace: #0 /home/meskholdings/mybluefile.com/change_password.php(22): PDOStatement->fetch(2) #1 {main} thrown in /home/meskholdings/mybluefile.com/change_password.php on line 22[/code]

For below code:

[code=php]$mysql_query = $mysql_connection->prepare(‘CALL sp_web_get_employee_by_password_guid(:param_guid, :param_code)’);
$mysql_query->bindParam(‘:param_guid’, $password_guid, PDO::PARAM_STR);
$mysql_query->bindParam(‘:param_code’, $activation_code, PDO::PARAM_STR);
$mysql_query->execute();

while($mysql_row = $mysql_query->fetch())
{
$full_name = $mysql_row[“official_name”];
$first_name = $mysql_row[“first_name”];
$email_address = $mysql_row[“email_address”];
}
[/code]

This is my SELECT SQL:

[CODE]CREATE DEFINER=`root`@`%` PROCEDURE `sp_web_get_employee_by_password_guid`(IN param_guid varchar(255), IN param_code varchar(255))
BEGIN
DECLARE param_employee_id INT;

IF EXISTS (SELECT employees.employee_id FROM employees JOIN employee_contacts ON employee_contacts.employee_id = employees.employee_id JOIN contact_category ON contact_category.contact_category_id = employee_contacts.contact_category WHERE new_password_guid = param_guid AND new_password_code = param_code AND contact_category.contact_category_type = “EMAIL” AND employee_contacts.use_for_communication = TRUE) THEN
BEGIN
SET param_employee_id = (SELECT employees.employee_id FROM employees JOIN employee_contacts ON employee_contacts.employee_id = employees.employee_id JOIN contact_category ON contact_category.contact_category_id = employee_contacts.contact_category WHERE new_password_guid = param_guid AND new_password_code = param_code AND contact_category.contact_category_type = “EMAIL” AND employee_contacts.use_for_communication = TRUE);

SELECT employees.employee_number, employees.first_name, employees.official_name, employee_contacts.contact_details AS email_address
FROM employees
JOIN employee_contacts ON employee_contacts.employee_id = employees.employee_id
JOIN contact_category ON contact_category.contact_category_id = employee_contacts.contact_category
WHERE employees.employee_id = param_employee_id AND contact_category.contact_category_type = “EMAIL” AND employee_contacts.use_for_communication = TRUE;
END;
END IF;

END[/CODE]

Thanks,
[URL=”http://www.cakeboutiquebh.com”]Jassim[/URL]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 18.2016 — My first guess would be that the execute if returning false, so I'd start by checking there:
[code=php]
if($mysql_query->execute() == false) {
die('<pre>execute failed:'.PHP_EOL.print_r($mysql_query->errorInfo(),1).'</pre>');
}
[/code]

That's just quick-and-dirty debug code. You'd want something "nicer" that did not display application data to the user in the final code -- maybe put it in a try/catch block with the catch logging the exception and displaying a generic "sorry" message.
Copy linkTweet thisAlerts:
@ginerjmMay 19.2016 — I may be seeing something new here and not familiar with it, so please enlighten me.

Is this a valid sql statement:
<i>
</i>('CALL sp_web_get_employee_by_password_guid(:param_guid, :param_code)');


What is the 'CALL' verb?
Copy linkTweet thisAlerts:
@NogDogMay 19.2016 — I assumed that's the syntax for calling the stored procedure -- but I'll admit I've never used it and did not check it in the manual. (I've only used stored functions in PostgreSQL, and only as triggered functions, not called from an application.)
Copy linkTweet thisAlerts:
@jrahmaauthorMay 19.2016 — I may be seeing something new here and not familiar with it, so please enlighten me.

Is this a valid sql statement:
<i>
</i>('CALL sp_web_get_employee_by_password_guid(:param_guid, :param_code)');


What is the 'CALL' verb?[/QUOTE]


Yes it is valid and I have been using it for long time for calling stored procedures.
Copy linkTweet thisAlerts:
@jrahmaauthorMay 19.2016 — My first guess would be that the execute if returning false, so I'd start by checking there:
[code=php]
if($mysql_query->execute() == false) {
die('<pre>execute failed:'.PHP_EOL.print_r($mysql_query->errorInfo(),1).'</pre>');
}
[/code]

That's just quick-and-dirty debug code. You'd want something "nicer" that did not display application data to the user in the final code -- maybe put it in a try/catch block with the catch logging the exception and displaying a generic "sorry" message.[/QUOTE]


I tried below code and I am getting connected but no result!

https://www.mybluefile.com/change_password.php?txtGuid=a&txtCode=b&txtPassword=123456

[code=php]// get employee details by guid;
$mysql_query = $mysql_connection->prepare('CALL sp_web_get_employee_by_password_guid(:param_guid, :param_code)');
$mysql_query->bindParam(':param_guid', $password_guid, PDO::PARAM_STR);
$mysql_query->bindParam(':param_code', $activation_code, PDO::PARAM_STR);
// $mysql_query->execute();

if($mysql_query->execute() == false)
{
die('<pre>execute failed:'.PHP_EOL.print_r($mysql_query->errorInfo(),1).'</pre>');
}
else
{
echo "connected<br><br>";
}
[/code]
Copy linkTweet thisAlerts:
@ginerjmMay 19.2016 — Since you seem to be new at adding error checking I'd just like to point out that your check was for the 'execute' statement, not the connect statement. Good practice would be to put a check on the connect call and then put a check on the execute. Your message of "connected" is mis-leading since it really indicates that the query ran. Of course it could only run if the connection had already run successfully, but I hope you get my meaning.
Copy linkTweet thisAlerts:
@jrahmaauthorMay 19.2016 — I also tried this but still no erro and no result as well..!

[code=php]try
{
// get employee details by guid;
$mysql_query = $mysql_connection->prepare('CALL sp_web_get_employee_by_password_guid(:param_guid, :param_code)');
$mysql_query->bindParam(':param_guid', $password_guid, PDO::PARAM_STR);
$mysql_query->bindParam(':param_code', $activation_code, PDO::PARAM_STR);

$mysql_query->execute();
}
catch( PDOException $Exception )
{
echo $Exception->getMessage();
}[/code]
Copy linkTweet thisAlerts:
@jrahmaauthorMay 19.2016 — Also when I run:

echo "Count: " . $mysql_query->rowCount();[/QUOTE]

I get zero but when I run my stored procedure on the server I get one row.
Copy linkTweet thisAlerts:
@NogDogMay 19.2016 — Also when I run:



I get zero but when I run my stored procedure on the server I get one row.[/QUOTE]


My first thought in that case would be that the parameters the code is passing to the function differ in some way than those you use when you test it manually, so you might want to take a closer look at those variables (var_export() is a good way to see exactly what an variable's value is, including type).
×

Success!

Help @jrahma spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...