Jump to content

Need bare bones sample code of charset-utf-8, MYSQLI handling.


yshua
Go to solution Solved by Christian F.,

Recommended Posts

Dear forum people:

 

        Have PHP5.3.8, MySQL5.5, Apache2.2, Win7 up and running.  Have spent a  lot of time trying to unravel how to take PHP file customer entries into MySQL database by using elaborate coding and working backwards.  Would just like to see some bare bones coding of the simplest of table database statements set up in MySQL, if charset-utf-8 needs to be specified. 

        And a simple Html turning to php file, which in turn allows for a customer input, turning straight to a mysqli data insert.  All of that would need an appropriate handling of charset-utf-8.  The simplest of examples will work, and I will expand it and modify it till the coding I was already given finally works.  Again, unsure if any table database statements specifying charset-utf-8 would even be needed....

 

Thanks,

Yshua :-\

Link to comment
Share on other sites

  • Solution

When creating the tables:

CREATE TABLE (....) DEFAULT CHARSET=utf-8;

 

Ensuring the correct HTTP header is sent:

header ("content-type: text/html; charset=utf-8");

 

Setting up the MySQL connection:

$db = new mysqli ();
$db->set_charset ('utf8');

 

If the tables are created without the proper charset, you can always use ALTER TABLE to correct that. I recommend using phpMyAdmin to help you do that, as it helps simplify the job.

If you need to do string manipulation, then you'll want to use the multibyte string functions.

For any Regular Expressions you might have you'll want to expand then to use /pL instead of \w, plus adding the 'u' flag, to make them compatible with all legal nationalized letters.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.