i connect to a mysql server and do a query on it. the query returns result when i do a set names query before or after开发者_如何学Go the main query,otherwise it returns null result. why is it so?
sounds like you have speacial chars in your query wich will cause trouble if you don't set the correct charset that should be used for sending the sql-query to the server. if you don't run 'set names' a the default value is used - and that seems to be the wrong one.
for more information, take a look at the documentation
Quoting from the MySQL manual:
SET NAMES indicates what character set the client will use to send SQL statements to the server
So it seems that you're writing a query in a charset which is not set to default in MySQL. You can try changing the default charset collation on both server and client to utf8, which should accept pretty much all characters.
More info here: http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html
精彩评论