Usa UTF-8 quando si creano tavolo.
create table table_name() CHARACTER SET = utf8;
Usa UTF-8 quando si inserisce al tavolo
set username utf8; INSERT INTO table_name (ABC,VAL);
Read More
And More
Codice dettagliata
Sotto codice è testato codice si prega di fare quanto segue è il suo lavoro.
Se è già stato creato il database, si prega di farlo come indicato di seguito. E se non hai creato il database, crealo e imposta Collation su utf8_unicode_ci
E lo stesso vale per la tabella definisce Collation come "utf8_unicode_ci" per i campi di tabella in cui si desidera memorizzare i caratteri di chines.
ALTER DATABASE `stackoverflow` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE TABLE `stackoverflow`.`chines`
(
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`words` VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE = InnoDB;
<?php
define('HOSTNAME', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '');
define('DATABASE', 'stackoverflow');
$dbLink = mysql_connect(HOSTNAME, USERNAME, PASSWORD)or die(mysql_error());
mysql_query("SET character_set_results=utf8", $dbLink)or die(mysql_error());
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db(DATABASE, $dbLink)or die(mysql_error());
mysql_query("set names 'utf8'",$dbLink)or die(mysql_error());
if(isset($_POST['addWord']))
{
mysql_query("SET character_set_client=utf8", $dbLink)or die(mysql_error());
mysql_query("SET character_set_connection=utf8", $dbLink)or die(mysql_error());
$sql_query = "INSERT INTO chines(words) VALUES('".$_POST['words']."')";
mysql_query($sql_query, $dbLink)or die(mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
</head>
<body>
<?php
mysql_query("SET character_set_results=utf8", $dbLink);
$sql_query = "SELECT * FROM chines";
$dbResult = mysql_query($sql_query, $dbLink)or die(mysql_error());
?>
<form action="" method="post">
<p>Word : <input type="text" name="words" /></p>
<p><input type="submit" name="addWord" /></p>
</form>
<?php
while($row = mysql_fetch_assoc($dbResult))
{
echo $row['words']. '<br />';
}
?>
</body>
</html>
vedere il risultato e passo visivo come di seguito.
fonte
2013-01-22 10:28:41
Qual è l'esatto messaggio di errore? usa 'mysqli_error()' per ottenerlo. Inoltre è meglio usare le nuove funzioni di mysqli come le vecchie funzioni di mysql saranno deprecate. – Tuim
[SQL Injection ha letto a riguardo ...] (http://en.wikipedia.org/wiki/SQL_injection) – PeeHaa
Sì, quel sito non durerà un'ora in natura. –