How come I get errors when using PHP PDO to run stored procedures?

by on September 21, 2009

Q: I am working with the PDO library in PHP to connect to MySQL and when I try to execute a stored procedure I get the following error:

trigger_error(“SQLSTATE[HY000]: General error”, “256”)

Any idea?


10 Responses to “How come I get errors when using PHP PDO to run stored procedures?”
  1.  

    You might find the comments on the PHP PDO MySQL manual page useful. Some say setting PDO to use UTF-8 might solve it and others say making sure the client and the server libraries match each other fix it.

    Is there any other information you get besides “General Error” because a lot of the results I see seem to say other stuff besides just that.

     
  2.  

    after general error i get code 256.
    thanks for the feedback

     
  3.  

    Right I see the 256, which should just mean you were disconnected. The General Error will sometimes come with more of a description and its own error code.

     
  4.  

    here is more: the error takes place when calling a stored procedure and generates the next error:

    trigger_error(“SQLSTATE[HY000]: General error”, “256”) # line 100, file: \database_handler.php
    DatabaseHandler.GetAll(“CALL catalog_get_products_in_category(

     
  5.  

    It seems like PHP is dumbing down the error for you. Every single General Error I find has “General Error: #### description”. So it says General Error but is followed by a 4 digit code and then the description.

    What operating system are you running the code on?

     
  6.  

    no other error, that is it. i am running windows vista.

    driving me crazy!! dunno of another alternative and agghhh

    thank you for following up

     
  7.  

    Okay I think I have pretty much confirmed that you cannot get a General Error without the information that comes with it. You, however, are missing the extra information due to a setting on your system. I really have no idea what setting causes MySQL to show/hide the extra information though. I just know that there is no record of a General Error without a 4 digit error code and a description anywhere that I can find.

    Now, with that said, since you are running this on Windows that just opened about 1 million more reasons this could be happening. Can you give us the SQL you are running (the entire $pdo->query()) and can you tell us what version of MySQL and PHP you are running?

     
  8.  

    here is the entire error:
    ERRNO: 256
    TEXT: SQLSTATE[HY000]: General error
    LOCATION: C:\Apache2\htdocs\tshirtshop\business\database_handler.php, line 100, at September 21, 2009, 12:48 pm
    Showing backtrace:
    trigger_error(“SQLSTATE[HY000]: General error”, “256”) # line 100, file: C:\Apache2\htdocs\tshirtshop\business\database_handler.php
    DatabaseHandler.GetAll(“CALL catalog_get_products_on_catalog(
    :short…”, Array[3]) # line 173, file: C:\Apache2\htdocs\tshirtshop\business\catalog.php
    Catalog.GetProductsOnCatalog(“1”, “1”) # line 54, file: C:\Apache2\htdocs\tshirtshop\presentation\products_list.php
    ProductsList.init() # line 16, file: C:\Apache2\htdocs\tshirtshop\presentation\smarty_plugins\function.load_presentation_object.php
    smarty_function_load_presentation_object(Array[2], Object: Application) # line 5, file: C:\Apache2\htdocs\tshirtshop\presentation\templates_c\%%10^108^1083067C%%products_list.tpl.php
    include(“C:\Apache2\htdocs\tshirtshop\presentation\templates_c\%%10^108^1…”) # line 1869, file: C:\Apache2\htdocs\tshirtshop\libs\smarty\Smarty.class.php
    Smarty._smarty_include(Array[2]) # line 12, file: C:\Apache2\htdocs\tshirtshop\presentation\templates_c\%%CC^CCA^CCA018F7%%first_page_contents.tpl.php
    include(“C:\Apache2\htdocs\tshirtshop\presentation\templates_c\%%CC^CCA^C…”) # line 1869, file: C:\Apache2\htdocs\tshirtshop\libs\smarty\Smarty.class.php
    Smarty._smarty_include(Array[2]) # line 35, file: C:\Apache2\htdocs\tshirtshop\presentation\templates_c\%%41^412^412F4E3D%%store_front.tpl.php
    include(“C:\Apache2\htdocs\tshirtshop\presentation\templates_c\%%41^412^4…”) # line 1256, file: C:\Apache2\htdocs\tshirtshop\libs\smarty\Smarty.class.php
    Smarty.fetch(“store_front.tpl”, null, null, true) # line 1106, file: C:\Apache2\htdocs\tshirtshop\libs\smarty\Smarty.class.php
    Smarty.display(“store_front.tpl”) # line 29, file: C:\Apache2\htdocs\tshirtshop\index.php

    RUNNING: php 5.3 and mysql 5.1.11

    I am going to test it on linux box…

    thanks!

     
  9.  

    I think you might be getting confused between the MySQL error and the PHP error. The backtrace that you posted is all PHP, it has nothing to do with MySQL other than MySQL returning an error code caused PHP to print out a backtrace.

    It looks like you have some code that catches any db errors and then does a backtrace and spits it all out. The problem is that this code is not actually displaying the full MySQL error information. You should have something like

    SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other
    unbuffered queries are active. Consider using PDOStatement::fetchAll().
    Alternatively, if your code is only ever going to run against mysql, you
    may enable query buffering by setting the
    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. HY000

    or

    SQLSTATE[HY000]: General error: 2053 Source File

    It would be helpful to see the actual query though because a lot of the stuff I see, esp related to Windows, is the 2014 error. On Windows this seems to be caused by running two queries or running a query with a comment. It looks like the fix is to remove the comment if you have a comment in there.

     
  10.  

    got it

    it was an issue with the sproc;