D
D
Derick Wire2015-12-15 01:31:04
WordPress
Derick Wire, 2015-12-15 01:31:04

How to get rid of question marks when adding to the database?

Good day, I'm learning to write plugins for vp, I ran into a problem, I created a table, I put records in it, and I see that instead of special characters there are question marks, as I do:
we have an array $songsid consisting of song titles:
1 => string 'Noir's áäéíóôúýľščťžňďŕĺ - Lumière Brillante' (length=62)
2 => string 'false - Lumiere Brillante - Out Now' (length=35)
3 => string 'Martin Garrix - Animal's (Original Mix)' (length=39)
4 => string 'Kiesza - Hideaway' (length=17)
5 => string 'hd - ' (length=5)
6 => string '96 - ' (length=5)
for the first track in the title, special characters
create an array with values ​​for recording :

foreach($songsid as $key => $value){
      $values[] = "('".$wpdb->escape($value)."', '0', '0', '0', '".date('Y-m-d')."')";
    }

add an entry:
$insert = "INSERT INTO `" . $table_statistics .
                "` (`name`, `time`, `count`, `download`, `date`) " .
                "VALUES".implode(",", $values);
    $results = $wpdb->query($insert);

at the output we have an added entry in the form
0 => 
    object(stdClass)[362]
      public 'id' => string '1' (length=1)
      public 'name' => string 'Noir\'s<b> áäéíóôúý?š??ž????</b> - Lumière Brillante' (length=56)
      public 'time' => string '0' (length=1)
      public 'count' => string '0' (length=1)
      public 'download' => string '0' (length=1)
      public 'date' => string '2015-12-14' (length=10)

how to treat it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
argenit, 2015-12-15
@argenit

Set the encoding. UTF-8 without BOM in plugin file.

P
Pavel K, 2015-12-15
@PavelK

What is the base encoding? The script file has already been mentioned.
Well, try:
mysql_query("SET CHARACTER SET utf8 ");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question