You can do it by adding
$db->set_charset("utf8"); // MySQL
mb_internal_encoding("UTF-8"); // Set PHP encoding
header("Content-Type: text/html; charset=utf-8"); // Prevent incorrect encoding in Browser
at the top and escaping every parameter using
$param=$db->escape_string($param);
Then MySQL/PHP will handle everything which is encoding-related for you. When you did this, all your stuff will be in UTF-8.
Your problem with the name is probably related to the header() command, that means that the browser choooses another charset than PHP. You can fix your data by doing that:
$data=utf8_encode($data);
If that produces bad results, try this one:
$data=utf8_decode($data);
After that everything should look fine.
If you want to make UTF8 the default charset, consider adding the following to my.cnf in [mysqld]:
# Set UTF-8 as standard
collation-server = utf8mb4_general_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
That's what I did, I haven't had any issues since a year of development with all what I mentioned in this post.