I've seen many ways of defining and might have created a mix of defining things on php. Can you help me edit thingws together:

<?php 
// for display
ob_start();
//header("Content-Type: text/html; charset=utf-8");
//header("Content-Type: text/html; charset=utf-8_general_ci");
//error_reporting(E_ALL);
ini_set('display_errors', true);
set_time_limit(480);
//define("DSN", "mysql:host=localhost;dbname=biblewheel;charset=utf-8");
define("DSN", "mysql:host=localhost;dbname=biblewheel;charset=utf-8_general_ci");

define("USERNAME", "root");

define("PASSWORD", "");

/*$pdo = new PDO('mysql:host=hostname;dbname=database', 'username', 'password',
	array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
*/

$options = array(PDO::ATTR_PERSISTENT =>true);

try{
	$conn = new PDO(DSN, USERNAME, PASSWORD, $options);
	//array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf-8_general_ci COLLATE utf8"); utf8mb4_bin
	//$conn = new PDO("mysql:host=localhost; dbname=biblewheel;charset=UTF8","root","",array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"))or die("no connection"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//echo "connection successful<br /><br />\n";
}catch (PDOException $ex){
	echo "A database error occurred ".$ex->getMessage();	
}

    It's not at all clear what you are trying to accomplish. I would point out that if you want your site to use the UTF8 charset, there are numerous places where you might need to specify this:
    when outputting your HTML, send headers that say it is utf8
    inside your HTML, declare that you are using utf8: <meta charset="UTF-8">
    when connecting to a database, declare the connection is utf8
    when defining your db tables, declare the table and your columns as utf8
    when reading input from files, either encode those files as utf8 or perform a conversion from their charset to utf8
    when saving your PHP source code, make sure it is utf-8 encoded (this may be an option in your editor)

      7 days later

      In your DSN you can change
      'charset=utf-8_general_ci'
      to
      'charset=utf8'

      This is what most script I have seen use.

      As sneakyimp tells, there are several places to set the charset.
      1. In the html
      2. iniset PHP default charset in PHP-ini.
      3. Like you are doing for the database connection.
      4. Also when creating database and tables.

        Write a Reply...