0

I am converting a php script to use prepared statements. But when I grab a piece of text from the database, special characters are replaced with a �.

Example:

The database contains the following text : test 'éï' test
(verified with phpadmnin it exists)

if ( $stmt = $mysqli->prepare ( "SELECT act_omschr FROM jag_activiteiten" ) )
{   
    $stmt->execute();
    $stmt->store_result();  
    $stmt->bind_result ( $DBomschrijving );
    $stmt->fetch();

    if ( $stmt->num_rows )
    {
        echo "$DBomschrijving";
    }

    $stmt->close();
}

As a result i get the following: test ���� test.

Any way to fix this?

Edits :

Changed my database tables to utf8_unicode_ci but it did not fix the issue. But combined with DDA's awnser below it did the trick.

$mysqli = new mysqli ( $loginURL, $dbusername, $dbpassword, $database );    
$mysqli->set_charset ( "utf8" );)
Bluestrike
  • 37
  • 1
  • 5
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Naruto Apr 01 '15 at 09:42

1 Answers1

1

for the same problem with PDO i use
$bdd=new PDO("mysql:host=$hostname_conn;dbname=$database_conn","$username_conn","$password_conn"); $bdd->EXEC('SET CHARACTER SET utf8');

... but your database has to be in utf-8

DDA
  • 161
  • 6
  • Thanks, In object oriented style it looks like this: $mysqli = new mysqli ( $loginURL, $dbusername, $dbpassword, $database ); $mysqli->set_charset ( "utf8" ); – Bluestrike Apr 01 '15 at 17:58
  • Thanks. Happy to see i could have help you. By the way, PDO is also an Oriented Object style. – DDA Apr 01 '15 at 18:57