Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tranquangchau/7ff1fbb6d271cbf2d520 to your computer and use it in GitHub Desktop.
Save tranquangchau/7ff1fbb6d271cbf2d520 to your computer and use it in GitHub Desktop.

Insert, Update database

must setting

in html

in php

in mysql

html

  • meta utf-8 ex:

php

for query mysql_query("SET NAMES utf8");

ex:

  • mysql_query("SET NAMES utf8");
  • $result = mysql_query("INSERT INTO comment(message) VALUES('".$_POST["txtmessage"]."')");

mysql

table: structure collection have utf-8

ex: database mc_data table comment column message structure collection utf8mb4_vietnamese_ci

#Select database demo

$connection = mysql_connect('localhost', 'user', 'pw');

mysql_select_db('yourdb', $connection);

mysql_query("SET NAMES 'utf8'", $connection);

// Now you get UTF-8 encoded stuff

$query = sprintf('SELECT name FROM place where id = 1');

$result = mysql_query($query, $connection);

$result = mysql_fetch_assoc($result);

@tranquangchau
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment