GoDaddy主机PHP5.6环境下mysqli get_result()报500错误求助
$stmt->get_result() in PHP 5.6 (GoDaddy Hosting) Hey there, let's break down why you're hitting that frustrating 500 error when calling $stmt->get_result() on your GoDaddy PHP 5.6 setup. I’ve dealt with similar issues on shared hosts with older PHP versions, so here’s what to check and fix:
1. The #1 Culprit: Missing mysqlnd Driver
The mysqli_stmt::get_result() method requires the MySQL Native Driver (mysqlnd) to work. Many shared hosts (including GoDaddy’s default PHP 5.6 configurations) use the older libmysqlclient driver instead, which doesn’t support this method. When you call it, PHP throws a fatal error that triggers the 500 status code.
How to Verify:
Create a quick phpinfo.php file with this code:
<?php phpinfo(); ?>
Upload it to your server and access it in your browser. Search for the term "mysqlnd" — if you don’t see it listed anywhere, your host isn’t using this driver.
Fix: Use bind_result() Instead
Since you might not have permission to install or switch drivers on GoDaddy, replace get_result() with bind_result() and fetch() to retrieve your data. This method works with both drivers. Here’s how to adjust your code:
$tel = $_POST['tel']; $stmt = $mysqli->prepare("select * from affeliate_db where tel=?"); // Note: If your "tel" field is a string (e.g., phone number with area code), use 's' instead of 'i' $stmt->bind_param('i', $tel); $stmt->execute(); // Bind result variables to match the order of columns in your SELECT query // Replace these with your actual table column names (e.g., id, tel, email, etc.) $stmt->bind_result($id, $tel, $column3, $column4); $userExists = false; // Fetch the first matching row (we don't need all rows for existence check) if ($stmt->fetch()) { $userExists = true; } if ($userExists) { echo "existed"; } else { echo "found usr"; } $stmt->close();
2. Check Server Error Logs for Exact Details
500 errors are generic — to get the real error message (like "Call to undefined method mysqli_stmt::get_result()"), check your GoDaddy error logs:
- Log into your cPanel.
- Look for the Error Log tool under the "Metrics" section.
- You’ll see the exact fatal error message that’s causing the 500 status.
If you want to temporarily see errors in the browser (only do this for debugging, not production), add these lines at the top of your script:
ini_set('display_errors', 1); ini_set('error_reporting', E_ALL);
3. Verify GoDaddy PHP Extension Settings
Sometimes switching to PHP 5.6 in cPanel doesn’t enable all required extensions:
- Go to cPanel’s Select PHP Version tool.
- Make sure
mysqliis checked (enabled). - Some GoDaddy plans let you switch the MySQL driver — look for a "MySQLnd" option and enable it if available.
4. Double-Check Variable Type Matching
You’re using bind_param('i', $tel) which treats $tel as an integer. If your tel database field is a string (e.g., phone numbers with + or non-numeric characters), this type mismatch could cause issues. Try changing the parameter type to 's' (string) instead:
$stmt->bind_param('s', $tel);
内容的提问来源于stack exchange,提问作者Wilf

