Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems in inserting utf-8 string into database and then outputting it to web page
    primarykey
    data
    text
    <p>I am learning PHP programming, so I have setup testing database and try to do various things with it. So situation is like that:</p> <p>Database collation is utf8_general_ci.</p> <p>There is table "books" created by query</p> <pre><code>create table books ( isbn char(13) not null primary key, author char(50), title char(100), price float(4,2) ); </code></pre> <p>Then it is filled with some sample data - note that text entries are in russian. This query is saved as utf-8 without BOM .sql and executed.</p> <pre><code>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); </code></pre> <p>When I review contents of created table via phpMyAdmin, I get correct results. </p> <p>When I retrieve data from this table and try to display it via php, I get question marks instead of russian symbols. Here is piece of my php code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Books&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?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-&gt;query($query); $num_results = $result-&gt;num_rows; for ($i = 0; $i &lt; $num_results; $i++) { $row = $result-&gt;fetch_assoc(); echo "&lt;p&gt;&lt;strong&gt;".($i+1).". Title: "; echo htmlspecialchars (stripslashes($row['title'])); echo "&lt;/strong&gt;&lt;br /&gt;Author: "; echo stripslashes($row['author']); echo "&lt;br /&gt;ISBN: "; echo stripslashes($row['isbn']); echo "&lt;br /&gt;Price: "; echo stripslashes($row['price']); echo "&lt;/p&gt;"; } ... </code></pre> <p>And here is the output:</p> <pre><code>1. Название: Java 2. ??????????? ???????????? Автор: ????? ?????? ISBN: 5-8459-0046-8 Цена: 34.99 </code></pre> <p>Can someone point out what I am doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload