Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:26:38+00:00 2026-06-07T05:26:38+00:00

$dbo = new PDO(mysql:host=localhost;dbname=database, databaseuser, databasepassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => SET NAMES utf8)); $dbo -> exec(set

  • 0
$dbo = new PDO("mysql:host=localhost;dbname=database", "databaseuser",
  "databasepassword", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$dbo -> exec("set character_set_client='utf8'");
$dbo -> exec("set character_set_results='utf8'");
$dbo -> exec("set collation_connection='utf8_general_ci'");
$prepSnapRetrieve = $dbo->prepare(
  "SELECT * FROM znc_log WHERE `nick` LIKE :u AND `tstamp` BETWEEN :t1 AND :t2"
);
$prepSnapRetrieve->execute(array(':u' => str_replace("|osu","", $_GET['u']),
  ':t1' => $_GET['sns'], ':t2' => $_GET['sne']));
$snapshotListing = $prepSnapRetrieve->fetchAll();
echo("Snapshot of ".$_GET['u']. "'s chat on ".strftime("%e/%m/%g",$_GET['sne']));
echo("<br><br>");
foreach($snapshotListing as $chat) {
  echo "<i>" . " " . "[" . strftime("%H:%M:%S", $chat['tstamp']) . "]" .
   "</i> " . " ><u>" . $chat['channel'] . "</u>< " . "(<b>" .
   htmlspecialchars($chat['nick'])."</b>) ".htmlspecialchars($chat['message']);
  echo("<br>");
}

This snippet is code is supposed to parse and output IRC data which has been stored in UTF-8 – but upon echoing, any unicode content simply appears as:

??????

I have reviewed several questions and included several purported fixes, but nothing appears to work. Another script using the same database echoes UTF-8 content perfectly, but it is using the standard MySQL implementation of PHP, and not PDO. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:26:40+00:00Added an answer on June 7, 2026 at 5:26 am

    There are multiple points of failure, when working with UTF8:

    • make sure the table is utf8

      Use SQL-Command Show Variables; to check the MySQL character settings for the table.

    • inserted data is utf8

      You might try tools like phpMyAdminer or Adminer to check, if the
      data is inserted correctly. Try to insert data via the tool manually.
      When inserting via script, do not use basic string functions. Always use their mbstring
      alternatives. Set mb_internal_encoding( 'UTF-8' ); to let PHP handle UTF-8 internally.

    • fetched data is utf8

      I would only use $pdo->exec("SET NAMES utf8"); and drop the rest. Because
      SET NAMES x is equivalent to
      SET character_set_client = x;
      SET character_set_results = x;
      SET character_set_connection = x;

    • displayed data is utf8

      If this is displayed in an html page, do not forget to set the meta tag or header
      "Content-Type: text/html; charset=utf-8".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php try { $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); $sql = $DBH->exec(" CREATE TABLE
So Far class PDOExtender { private $_DBO; public function openConnection() { $dsn = mysql:host=.DB_HOST.;dbname=.DB_NAME;
ALTER PROCEDURE [dbo].[AmendInsertDuplicateFields] (@ReportID varchar(50)) AS BEGIN DECLARE @NewReportID VARCHAR(50) SET @NewReportID = NEWID()
UPDATE DB4010.dbo.EntityStagedData SET EntityData = ( SELECT geo.City + ' ' + geo.Description +
I'm new to triggers . I have table like this CREATE TABLE [dbo].[Positions]( [Id]
here is my code SqlCommand insert_user = new SqlCommand(insert into dbo.users (username,password,firstname,lastname,address,country,city,phonenumber,gender,email) VALUES ('
SqlConnection connection = new SqlConnection(cnnString); try { connection.Open(); SqlCommand command = new SqlCommand([dbo].[tblMessages_Insert], connection);
I open a new window in SSMS and run this: SET ANSI_DEFAULTS ON GO
Using SQL Server 2000 I make a trigger in new database CREATE TRIGGER [CARDEVENTSAVING]
I'm new to T-SQL; all my experience is in a completely different database environment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.