2

I have problem with getting records from database when I have words with German letters in SQL query, when I do it in phpAdmin it gives 88 rows with results, when I want to execute the same query but in php code it gives me bool(false). In db I use utf8_bin. What is wrong?

$getPapers = mysql_query("SELECT * FROM swt_pubs WHERE column LIKE '%Aß%' ORDER BY id DESC LIMIT 10");
echo $getPapers;
while ($papers = mysql_fetch_object($getPapers)) {
    echo "string";
    echo convertToUTF8($papers->content);
}
var_dump($papers);?>

Results which I get:

Resource id #6

bool(false)

Edit 1: I have this coding of page:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

Edit 2:

function convertToUTF8 ($string)
        {
        return str_replace ('Ä', '&#196;',
               str_replace ('„', '&#132;',
               str_replace ('“', '&#147;',
               str_replace ('–', '&#150;',
               str_replace ('­', '&#173;',
                    str_replace ('È', '&#200;',
                        str_replace ('É', '&#201;',
                            str_replace ('Ö', '&#214;',
                                str_replace ('Ü', '&#220;',
                                    str_replace ('ß', '&#223;',
                                        str_replace ('ä', '&#228;',
                                            str_replace ('è', '&#232;',
                                                str_replace ('é', '&#233;',
                                                    str_replace ('ö', '&#246;',
                str_replace ('ü', '&#252;',
                    str_replace ('@', '&#64;',
                        str_replace ('Ã?', '&#220;',
                            str_replace ('\"', '"',
                            str_replace ("\'","'",
                                ersetzeBbCode ($string)
                                    ))
                                ))
                            )
                        )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
             ))
            );
        }
Community
  • 1
  • 1
Beacze
  • 534
  • 3
  • 8
  • 24
  • 1
    Is your PHP source file also encoded in UTF8 or not ? If it is not, the query executed by MyQSL might not be what you wrote in your source code. – Mat Jun 23 '15 at 18:49
  • 1
    Are you importing a library or do you have a function called `convertToUTF8`? If I had to wager a guess, either that function or `$papers->content` is your issue. – the_pete Jun 23 '15 at 18:49
  • `convertToUTF8()` is not a PHP function so show us the code for that function – RiggsFolly Jun 23 '15 at 18:50
  • @the_pete : According to the output, `convertToUTF8` is not called. I don't think it's the issue – Mat Jun 23 '15 at 18:51
  • @Mat Yes I think it is, its the `var_dump()` that she forgot to show us – RiggsFolly Jun 23 '15 at 18:52
  • http://stackoverflow.com/questions/10929836/utf8-bin-vs-utf-unicode-ci might explain why the collation makes the query return no results (the composition of the character `ß` is not the same in the source code than in the DB and utf8_bin compares them blindly while utf8_general_ci is clever) – Mat Jun 23 '15 at 18:54
  • @MarcB `mysql_fetch_object` returns false if there are no more rows [documentation](http://php.net/manual/en/function.mysql-fetch-object.php) – Mat Jun 23 '15 at 19:00
  • @Mat: aww, poop. right. that's a post-loop var_dump. apologies... – Marc B Jun 23 '15 at 19:03
  • I have added function convertToUTF8() var_dump($papers) gives bool(false) – Beacze Jun 23 '15 at 19:11
  • but it doesn't display even this echo "string";, so it looks like it never gets to this while – Beacze Jun 23 '15 at 19:13
  • it means that your `query` is invalid or its not returning any results. – cmorrissey Jun 23 '15 at 19:18
  • but whenI put this string directly in phpAdmin it gives results back, and in case if would look like that LIKE '%Ab%' it also gives result back,only in case if I use German results it has no results – Beacze Jun 23 '15 at 19:21
  • To be quite blunt, that `convertToUTF8` is a joke. It has to be. Right?! – deceze Jun 23 '15 at 20:04

2 Answers2

1

use uft8-general-ci that solve your problem

tapos ghosh
  • 2,114
  • 23
  • 37
1

one interesting thing is most of the time we upload large file using sql server but it the file has any unicode character then we get it in any language but the unicode word can't work . to solve this problem when you upload sql file add this life in your sql file :

SET NAMES utf8;

then your all problem easily solve

tapos ghosh
  • 2,114
  • 23
  • 37