I am learning programming in PHP, so I have set up a test database and try to do different things with it. So the situation is this:
The database mapping is utf8_general_ci.
There is a “book” table created upon request
create table books ( isbn char(13) not null primary key, author char(50), title char(100), price float(4,2) );
Then it is filled with some examples of data - note that the text entries are in Russian. This request is saved as utf-8 without the .sql specification and is executed.
insert into books values ("5-8459-0046-8", " ", "Java 2. ", 34.99), ("5-8459-1082-X", " ", "Linux. ", 24.99), ("5-8459-1134-6", " ", "CorelDRAW X3. ", 24.99), ("5-8459-0426-9", " ", " Linux", 49.99);
When I view the contents of the created table via phpMyAdmin, I get the correct results.
When I extract data from this table and try to display it through php, I get question marks instead of Russian characters. Here is a snippet of my php code:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Books</title> </head> <body> <?php header("Content-type: text/html; charset=utf-8"); mysqli_set_charset('utf8'); @ $db = new mysqli('localhost', 'login', 'password', 'database'); $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; for ($i = 0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars (stripslashes($row['title'])); echo "</strong><br />Author: "; echo stripslashes($row['author']); echo "<br />ISBN: "; echo stripslashes($row['isbn']); echo "<br />Price: "; echo stripslashes($row['price']); echo "</p>"; } ...
And here is the conclusion:
1. : Java 2. ??????????? ???????????? : ????? ?????? ISBN: 5-8459-0046-8 : 34.99
Can someone point out what I'm doing wrong?