2013-04-03 4 views
8

मैंने अपनी रजिस्ट्री स्क्रिप्ट को mysql से mysqli में परिवर्तित कर दिया है। मैं ठीक काम किया mysql के रूप में, लेकिन यह अब मुझे त्रुटिMySqli सिंक से बाहर संचार; आप अब इस आदेश को नहीं चला सकते

Commands out of sync; you can't run this command now 

देता है इस समारोह मैं उपयोगकर्ता

function register_user($register_data) { 
global $myConnection; 
array_walk($register_data, 'array_sanitize'); 
//Make the array readable and seperate the fields from data 
$fields = '`' . implode('`, `', array_keys($register_data)) . '`'; 
$data = '\'' . implode('\', \'', $register_data) . '\''; 
//Insert the data and email an activation email to the user 
mysqli_query($myConnection, "INSERT INTO `members` ($fields) VALUES ($data)") or die(mysqli_error($myConnection)); 
email($register_data['mem_email'], 'Activate your account', "Hello " . $register_data['mem_first_name'] . ",\n\nThank you for creating an account with H Fencing. Please use the link below to activate your account so we can confirm you identity:\n\nhttp://blah.blah.co.uk/activate.php?mem_email=" . $register_data['mem_email'] . "&email_code=" . $register_data['email_code'] . "\n\n - David & Jay "); 
} 

ईमेल मेरी सरणी से सही डेटा के साथ ठीक भेजता है रजिस्टर करने के लिए इस्तेमाल करते हैं। हालांकि डेटाबेस में कोई डेटा डाला नहीं गया है और मुझे ऊपर वर्णित त्रुटि मिलती है। मैं पहले कभी इस त्रुटि में नहीं आया है।

+3

1. इसे चलाने से पहले क्वेरी को प्रिंट करें और इसे देखें। 2. अपनी क्वेरी को पैरामीटरेट करें। 3. भगवान के प्यार के लिए, अपनी क्वेरी पैरामीटर करें। – Sammitch

उत्तर

9

यदि आपको सिंक से बाहर संचार मिलता है; आप अब इस आदेश को अपने क्लाइंट कोड में नहीं चला सकते हैं, आप क्लाइंट फ़ंक्शंस को गलत क्रम में कॉल कर रहे हैं।

यह हो सकता है, उदाहरण के लिए, यदि आप mysql_use_result() का उपयोग कर रहे हैं और mysql_free_result() कहने से पहले एक नई क्वेरी निष्पादित करने का प्रयास करें। यह तब भी हो सकता है जब आप दो प्रश्नों को निष्पादित करने का प्रयास करते हैं जो mysql_use_result() या mysql_store_result() को कॉल किए बिना डेटा लौटाते हैं।

यहाँ से: http://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html

अद्यतन

आप क्वेरी के लिए एक चर बनाने के लिए और चर MySQL Workbench की तरह कुछ में सीधे पेस्ट आप वाक्य रचना निष्पादन से पहले जांच कर सकते हैं।

<?php 
      function myConnection(){ 
       $myConnection = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db'); 
       return $myConnection; 
      } 


    function register_user($register_data) { 
     array_walk($register_data, 'array_sanitize'); 
     //Make the array readable and seperate the fields from data 
     $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; 
     $data = "'" . implode("', '", $register_data) . "'"; 
     //Insert the data and email an activation email to the user 
     $query = "INSERT INTO `members` ($fields) VALUES ($data)"; 
        $myNewConnection = myConnection();   

        if($result = mysqli_query($myNewConnection, $query)){ 
     email($register_data['mem_email'], 'Activate your account', "Hello " . $register_data['mem_first_name'] . ",\n\nThank you for creating an account with H Fencing. Please use the link below to activate your account so we can confirm you identity:\n\nhttp://blah.blah.co.uk/activate.php?mem_email=" . $register_data['mem_email'] . "&email_code=" . $register_data['email_code'] . "\n\n - David & Jay "); 
     mysqli_free_result($result); 
     return ("Success"); 
     } else { 
      echo $query; 
      die(mysqli_error($myNewConnection)); 
     } 

    } 

?> 
+0

मैंने क्वेरी को सीधे PHPmyadmin में चिपकाया और यह ठीक डाला, जिसका अर्थ है कि वास्तविक क्वेरी – jhetheringt7

+0

काम करती है क्या आपने इस कोड को mysqli_free_result भाग के साथ आजमाया है? –

+0

हां, हालांकि यह क्या करता है, अन्य कथन चलाता है और अगर कथन – jhetheringt7

संबंधित मुद्दे