Maintenance

  • Home
  • Log in
  • « Learning Docker
  • Configuring eXist/Jetty for single app deployment »

UTF8 in php and mysql

Posted by sarneil on 23 Nov 2016 in Activity log

Reminding myself of the 3 steps to ensure UTF gets from form via php to mysql database and back via php to report:

1) In each php page put the following meta tag in the head element
<meta charset="utf-8"/>

2) Immediately after creating the object that connects to the DB tell it to use UTF8
mysqli
$mysqliConn = new mysqli($DBHost, $DBUser, $DBPass, $DBDatabase);
$mysqliConn->query('SET NAMES utf8');
$mysqliConn->query('SET CHARACTER SET utf8');
PDO
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8", $username, $password);
$conn->exec("set names utf8");

3) In the database (and each table) make sure the character encoding / collation is something like utf8_unicode_ci

This entry was posted by Stewart and filed under Activity log.

Maintenance

This blog is the location for all work involving software and hardware maintenance, updates, installs, etc., both routine and urgent.
  • Home
  • Recently
  • Archives
  • Categories

Search

Categories

  • All
  • Announcements
  • Hit by a bus
  • Labs
    • Activity log
    • Documentation
  • Notes
  • R & D
    • Activity log
    • Documentation
  • Servers
    • Activity log
    • Documentation
  • Tasks

All blogs

  • Academic
  • AdaptiveDB
  • Admin
  • Announcements
  • CanMys
  • Cascade
  • CGWP
  • ColDesp
  • Depts
  • DVPP
  • Endings
  • HCMC Blogs
  • Landscapes
  • LEMDO
  • Linguistics
  • Maint
  • LondonMap
  • Mariage
  • MoM
  • Moses
  • Pro-D
  • Projects
  • ScanCan
  • HumsSites
  • Wendat

This collection ©2022 by admin • Help • b2