سؤال

عندما أحاول استدعاء إجراءات المتجر في MySQL التي ترسل مجموعة نتائج ، فإنها تستمر في قول لي أنه "لا يمكن إرجاع نتيجة في السياق المعطى".

لقد قلت بعضها وقل البعض إنه خطأ mysql ، قال البعض إنه يجب عليك تغيير سائق mysqli الخاص بك و ....

الموقف :

باستخدام MySqli Driver Client Client API الإصدار 5.0.51a ، الإصدار PHP 5.2.4-2ubuntu5.6 ، باستخدام محول Zend 1.9 RC 1 MySqli.

ماذا علي أن أفعل!؟

هل كانت مفيدة؟

المحلول

لست متأكدًا من أن هذا هو الحل لمشكلتك ، ولكن ماذا عن المحاولة مع إصدار أحدث من PHP؟
PHP 5.2.4 بالتأكيد قديم جدًا - لذا ، إذا كان خطأ في برنامج تشغيل MySqli الخاص بـ PHP ، فقد يكون قد تم تصحيحه منذ ...

في الواقع ، بعد البحث السريع ، يبدو أن مشكلة مثل تلك التي تشهدها قد تم تقديمها بين PHP 5.2.3 و PHP 5.2.4 (وكانت لا تزال هنا في PHP 5.2.5).
نرى الخطأ رقم 42548: الإجراء XXX لا يمكن إرجاع نتيجة محددة في السياق المحدد (يعمل في 5.2.3 !!)

هل أنت قادر على الاختبار بشيء مثل PHP 5.2.9 أو 5.2.10؟
أعلم أن هذه لا يتم توفيرها من قبل Ubuntu ، حتى في آخر إصدار مستقر Ubuntu:-(قد تضطر إلى التجميع من المصادر :-(


هناك فكرة أخرى تتمثل في تجربة محول Mith PDO_MYSQL: ربما ستعمل مع ذلك؟
قد يكون من الممكن تغيير المحول دون التسبب في الكثير من المتاعب / دون أخذ ساعات للاختبار؟


نظرًا لأنك تعمل مع Zend Framework 1.9 ، فإليك منشورًا آخر قد يهمك ، وقد يكون من الأسهل اختباره: خطأ الإجراء المخزن بعد الترقية إلى 1.8

حل سهل لمحاولة العودة إلى Zend Framework 1.7 ؛ هل سيكون من الممكن بالنسبة لك ، فقط للاختبار؟


حظا سعيدا على أي حال !
وإذا وجدت الحل ، فلا تنس أن تشير إلى ما هي المشكلة ، وكيف قمت بحلها ؛-)

نصائح أخرى

الجواب هو ترقية PHP الخاص بك ، لقد قمت فقط بترقية لي إلى 5.3.0 ، وهو يعمل يحب الحلوى!

I had this problem recently on a contract. The client was using a codebase on windoze and php 5.2.6 and my installation was linux and php 5.3.1 Whatever we did, they wouldn't co-operate so in the end they gave me a windoze vista machine and we installed php 5.2.6 and off we went. Moral of the story: version matching counts. Weird cus I never had this ever before in any other job. But hey, you can't know everything. Very definitely not a MySql issue, just PHP.

It works perfectly with PHP 5.2.10 as well.

From an earlier version, I've successfully used mysqli::multi_query to call a problematic procedure and get the right results.

I know this question is ancient, but for those still working with 5.2.4 and getting this error, you may consider creating a new mysql PDO object to work around this problem.

I still use 5.2.4 on my dev server to ensure backward compatibility for the WordPress plugins I develop.

Below is a wrapper around procedural calls that I use to successfully call procedures in both 5.2.4 (run on my dev server) , which would normally give me the error, and my production server (which runs a newer version that doesn't give the error) .

Its WordPress specific, but it wouldn't be difficult to modify it using straight php.

/*
* Need to cache connection so we don't keep creating connections till we hit max.
*/

private $_dbhCache=null; 

/**
     * mySQL Call Proc
     *
     * Provides a wrapper around calling a mySQL stored procedure to ensure against a 5.2.4 bug that 
     * causes procedure calls to fail.
     * Error:'can't return a result set in the given context'
     * 
     * references:
     * http://stackoverflow.com/questions/1200193/cant-return-a-result-set-in-the-given-context
     * http://php.net/pdo_mysql#69592  //i got empty result set but pointed me in the right direction
     * http://php.net/pdo_mysql#80306 //this worked, but returned 0-indexed and assoc, i edited it so it only returns assoc mimicking $wpdb->get_results(
     * http://www.php.net/manual/en/pdo.connections.php
     * http://www.php.net/manual/en/pdostatement.fetch.php explains about FETCH_ASSOC
     * 
     * @param string $proc The mySQL stored procedure string, including paramaters, but without the call statement. e.g.: "my_procedure_name('my_paramater')"; 
     * @return string The results of the procedure call
     */
    public function mySQLCallProc( $proc ) {
        global $wpdb;
        $query = "call $proc";

        try {

            /*
             * Attempt to call the procedure normally.
             * 
             */

            $query_result = $wpdb->get_results( $query, ARRAY_A );

            /*
             * Check for a database error
             * and throw an exception if one is found.
             * We can then attempt it again using a workaround.
             */

          if ( $wpdb->last_error !== '' ) { 



                throw new Exception( 'Database Error While Calling Procedure' );
}

        } catch ( Exception $e ) {

            try {

                /*
                 * Create a PDO Object for the connection
                 */
  if ( is_null($this->_dbhCache)) {
                    $dbh = new PDO( 'mysql:host=' . DB_HOST . ';port=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD, array( PDO::ATTR_PERSISTENT => true ) );
 $this->_dbhCache=$dbh ;            
}else{
     $dbh = $this->_dbhCache;
}
                /*
                 * Prepare and call the procedure.
                 */
                $stmt = $dbh->prepare( "call $proc" );

                $stmt->execute();

                /*
                 *  fetch all rows into an associative array.
                 */

                $query_result = $stmt->fetchAll( PDO::FETCH_ASSOC ); //FETCH_ASSOC gets results as an assoc array. without it, you'll receive both assoc and 0-indexed array





    } catch ( PDOException $e ) {

                    print "Error!: " . $e->getMessage() . "<br/>";
    die();

    }


    }

        return ($query_result);


    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top