MySQLi connection issue

I have a *very* old php app (php 5.5.9) that I'm in the process of migrating over to a Nextjs React App but my first step was to try to migrate my database from AWS to Cloud SQL. I successfully copied my data over and started the database. I'm able to connect from the command line mysql client. 
```
mysql --version
mysql Ver 15.1 Distrib 5.5.68-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
```
So I don't believe I have any firewall or networking obstacles in place. But when I try to connect from mysqli I get an error message. To simplify things I created a basic connection test script. 
```

php // doesn't like the php tag in my post
ini_set('display_errors', 1);
error_reporting(E_ALL);
 
 
/****** Database Connection Settings ******/
 
// Database Connection Host (localhost by default)
//define('DATABASE_HOST', 'cloud-hostname');
define('DATABASE_HOST', 'aws-hostname');
 
// Database User
//define('DATABASE_USER', 'cloudSQL-user');
define('DATABASE_USER', 'aws-user');
 
// Database Password
//define('DATABASE_PASS', 'cloud-passwd');
define('DATABASE_PASS', 'aws-passwd');
 
// Default Database that will be connected to
define('DATABASE_DEFAULT', 'database_name');
 
print("This page works!");
$my_db_conn = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_DEFAULT);
mysqli_options($my_db_conn, MYSQLI_OPT_CONNECT_TIMEOUT, 30);
 
if ($my_db_conn->connect_error) {
die("Connection failed: " . $my_db_conn->connect_error);
} else {
print "Connected successfully";
}
 
?>
```
When I uncomment the aws connection definitions I get the following results
```
This page works!
Connected successfully
```
When I uncomment the cloudSQL connection definitions (commenting out the aws one's of course) I get the following result
```
Warning: mysqli::mysqli(): Server sent charset (255) unknown to the client. Please, report to the developers in /var/www/<my-url>/httpdocs/db_test_file.php on line 24
 
Warning: mysqli::mysqli(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers in /var/www/<my-url>/httpdocs/db_test_file.php on line 24
 
Warning: mysqli_options(): Couldn't fetch mysqli in /var/www/<my-url>/httpdocs/db_test_file.php on line 25
Connection failed: Server sent charset unknown to the client. Please, report to the developers
```
Please keep in mind the *same* credentials are working from the command line and *this* is working to connect to aws. but it doesn't work from mysqli - Any thoughts? 
Solved Solved
0 1 452
1 ACCEPTED SOLUTION

Figured it out. As the error states. the charset was different on the two servers. Just had to set `character_set_server` on my Google Cloud SQL to latin1 and now I can connect. 

View solution in original post

1 REPLY 1

Figured it out. As the error states. the charset was different on the two servers. Just had to set `character_set_server` on my Google Cloud SQL to latin1 and now I can connect.