Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在mysql中插入阿拉伯字母_Php_Mysql_Unicode_Internationalization_Arabic - Fatal编程技术网

Php 如何在mysql中插入阿拉伯字母

Php 如何在mysql中插入阿拉伯字母,php,mysql,unicode,internationalization,arabic,Php,Mysql,Unicode,Internationalization,Arabic,我在网上到处寻找,试图找到一个关于通过HTML和PHP将阿拉伯字母插入mysql的教程 我的HTML页面如下所示 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http

我在网上到处寻找,试图找到一个关于通过HTML和PHP将阿拉伯字母插入mysql的教程

我的HTML页面如下所示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
// Connects to your Database 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("castt") or die(mysql_error()); 
mysql_query("SET NAMES 'cp1256'"); 
mysql_query('SET CHARACTER SET cp1256'); 
当我浏览mysql数据库时,它看起来像“??”


有什么建议吗?

当您将输出声明为UTF-8时,您正在使数据库使用
cp1256
。那不行


cp1256
替换为
UTF8
可能已经有所帮助。

我通过添加

mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");

连接完成后马上就开始工作了 让我给你看看代码

步骤1创建数据库表

CREATE TABLE `language_messages` (
  `lang_id` int(11) NOT NULL auto_increment,
  `en` varchar(500) NOT NULL,
  `ar` varchar(500) NOT NULL,
  PRIMARY KEY  (`lang_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

INSERT INTO `language_messages` VALUES (1, 'About Us', 'من نحن');
INSERT INTO `language_messages` VALUES (2, 'Contact Us', ' تواصل معنا ');
INSERT INTO `language_messages` VALUES (5, '', 'శ్రీనివాస్ తామాడా');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--<html  dir="rtl" lang="ar" xml:lang="ar" xmlns="http://www.w3.org/1999/xhtml">-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php 

$sql = "select * from language_messages";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($res))
{
        echo"<br />". $row['en'];   
        echo"<br />". $row['ar'];   
    }

?>
</body>
</html>
步骤2创建连接

$conn=mysql_connect(HOST,DB_USER,DB_PASS) or die(mysql_error());
$db=mysql_select_db(DB_NAME,$conn) or die(mysql_error());
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
步骤3在HTML页面中查看输出

CREATE TABLE `language_messages` (
  `lang_id` int(11) NOT NULL auto_increment,
  `en` varchar(500) NOT NULL,
  `ar` varchar(500) NOT NULL,
  PRIMARY KEY  (`lang_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

INSERT INTO `language_messages` VALUES (1, 'About Us', 'من نحن');
INSERT INTO `language_messages` VALUES (2, 'Contact Us', ' تواصل معنا ');
INSERT INTO `language_messages` VALUES (5, '', 'శ్రీనివాస్ తామాడా');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--<html  dir="rtl" lang="ar" xml:lang="ar" xmlns="http://www.w3.org/1999/xhtml">-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php 

$sql = "select * from language_messages";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($res))
{
        echo"<br />". $row['en'];   
        echo"<br />". $row['ar'];   
    }

?>
</body>
</html>

无标题文件

但正如我前面提到的,我尝试了你的建议,但没有成功。谢谢你回答发生了什么事?你得到了什么?你的数据库是什么样的排序规则?相关的好阅读: