0
 try{
        echo("trying");//this prints
        mysql_set_charset('utf8'); //if I remove this everything is fine
        echo("success"); //this fails
    }catch(Exception $e){
        echo "problem $e";//this doesn't print
        throw new Exception("can't set charset",0, $e);//this does nothing
    }

I am introducing spanish characters into my otherwise working code and I'm running into a black hole. I have no idea what the problem is because php just goes off into la-la land and does nothing more after the mysql_set_charset('utf8'); line. When that line is commented out everything works perfectly. Where do I go looking for the error logs? I'm not the sysadmin on the server, so, I'm not sure how the php/mysql was configured. It's a linux box, and I'm assuming it's in some standard configuration, but I'm not finding a logs directory anywhere near php, so, I'm unclear on what I can do to figure out what it doesn't like here.

Oh, and without this line the text comes back featuring a black diamond with a question mark in it for every character that is UTF-8... so... that's the issue I'm actually trying to solve. Perhaps there's a different approach?

000
  • 26,951
  • 10
  • 71
  • 101
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236

2 Answers2

0

not sure, but the PHP manual says mysql_set_chartset will be deprecated and removed in the future.

http://php.net/manual/en/function.mysql-set-charset.php

that might be the source of your problem.

John Smith
  • 55
  • 1
  • 10
-1

I always used this and worked fine. Try it also without single quotes (I can't see the code now):

mysql_query("SET NAMES 'utf8'");

Edit

mysql_set_charset() doesn't throw exceptions. It is procedural style. You will find errors by mysql_error().

Note That Using mysql_set_charset is the preferred way to change the charset. Using mysql_query() to set it (such as SET NAMES utf8) is not recommended. Also, using mysqli_set_charset is prefered, as mysql_set_charset is deprecated from PHP 5.5.0. So, don't use mysql_query to set charset, nor use mysql_set_charset. Use instead mysqli_set_charset!

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Fanda
  • 3,760
  • 5
  • 37
  • 56