Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2018, 10:21 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default how to define charset UTF-8

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 Code:
<?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(DSNUSERNAMEPASSWORD$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_ERRMODEPDO::ERRMODE_EXCEPTION);
    
    
//echo "connection successful<br /><br />\n";
}catch (PDOException $ex){
    echo 
"A database error occurred ".$ex->getMessage();    
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with the charset when I get data from my db. Varg_88 Classic ASP Databases 0 January 8th, 2014 03:01 PM
page.response.charset manoj.aggarwal ASP.NET 2.0 Professional 0 August 1st, 2007 03:55 AM
charset question Edward King Pro JSP 1 August 8th, 2005 03:09 PM
change charset vincentc Classic ASP Basics 1 May 31st, 2005 04:00 AM
charset encoding bservi XML 0 May 3rd, 2004 07:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.