如何使用PHP在oracle 11G数据库中存储/检索中文字符? [英] How to store/retrieve chinese characters in oracle 11G database using PHP?
问题描述
我想使用ajax概念将html页面中的中文字符存储到oracle数据库中。
前端:HTML& PHP。
后端:Oracle 11G。
Oracle特性:
NLS_LANGUAGE = AMERICAN
NLS_CHARACTERSET = AL32UTF8
NLS_NCHAR_CHARACTERSET = AL16UTF16
以上特征无法更改。
< b>我尝试了什么:
当我尝试使用表单存储中文字符时提交它已成功存储,如果我尝试通过ajax存储我是在数据库中获得奇怪的字符。
在ajax页面中我添加了这一行:
header ( Content-type:text / html; charset = utf-8); $ p html页面中的$ p>
添加了以下行:
< meta http-equiv = Content-type value = text / html; charset = utf-8 >
i经历了多次堆栈溢出建议但没有好运。
请告诉我如何解决这个问题。
提前致谢。
代码:HTML Code。
< html >
< head >
< meta http -equiv = 内容类型 value = text / html; charset = utf-8 >
< title > 测试< / title >
< script src = jquery.min.js > < / script >
< script > ;
function addForm()
{
var englis h = document .getElementById(' txt_english')值;
var id = document .getElementById(' txt_id')。value;
var chinese = document .getElementById(' txt_chinese')。value;
$ .ajax(
{
type: POST ,
async: false ,
url: ajax / ajax_add_form.php,
数据:
{
english:english,
chinese:chinese,
id:id
}
})。done(
function (html)
{
alert(html);
});
}
< / 脚本 >
< / head >
< body >
< input type =' text' name < span class =code-keyword> =' txt_id' id =' txt_id' value =' ' < span class =code-attribute> / > < br >
< input 类型 =' text' 名称 =' txt_english' id =' txt_english' value =' ' / >
< 输入 type =' < span class =code-keyword> text' name =' txt_chinese' id =' txt_chinese' value =' ' / >
< 按钮 类型 = 按钮 > 点击我!< / button >
< < span class =code-leadattribute> / body >
< / html >
PHP代码:ajax / ajax_add_form.php
<?php
header( Content-type:text / html; charset = utf-8);
include( ../ config.php );
extract($ _ REQUEST);
$ sql = oci_parse($ conn, insert into test(id,english,chinese)values('。$ id。 ','。$ english。 ','。$ chinese。< span class =code-string> '));
oci_execute($ sql);
echo success;
?>
解决方案
.ajax(
{
类型: POST,
async: false ,
url: ajax / ajax_add_form.php,
data:
{
english:english,
chinese:chinese,
id:id
}
})。完成(
function (html)
{
alert(html);
});
}
< / 脚本 >
< / head >
< body >
< input type =' text' name < span class =code-keyword> =' txt_id' id =' txt_id' value =' ' < span class =code-attribute> / > < br >
< input 类型 =' text' 名称 =' txt_english' id =' txt_english' value =' ' / >
< 输入 type =' < span class =code-keyword> text' name =' txt_chinese' id =' txt_chinese' value =' ' / >
< 按钮 类型 = 按钮 > 点击我!< / button >
< < span class =code-leadattribute> / body >
< / html >
PHP代码:ajax / ajax_add_form.php
<?php
header( Content-type:text / html; charset = utf-8);
include( ../ config.php );
extract(
_REQUEST);
sql = oci_parse(
i want to store chinese characters from an html page into oracle database using ajax concept.
Front end : HTML & PHP.
Back end : Oracle 11G.
Oracle Characteristics:
NLS_LANGUAGE = AMERICAN
NLS_CHARACTERSET = AL32UTF8
NLS_NCHAR_CHARACTERSET = AL16UTF16
The above characteristics cannot be changed.
What I have tried:
when i try to store chinese character using form submit it's storing successfully, if i try to store through ajax i am getting weird characters in the database.
in the ajax page i have added this line:
header("Content-type: text/html; charset=utf-8");
in the html page added the below line:
<meta http-equiv="Content-type" value="text/html; charset=utf-8">
i have gone through many stack overflow suggestions but no luck.
please advice me on how to solve this.
Thanks in advance.
Code:HTML Code.
<html>
<head>
<meta http-equiv="Content-type" value="text/html; charset=utf-8">
<title>Test</title>
<script src="jquery.min.js"></script>
<script>
function addForm()
{
var english=document.getElementById('txt_english').value;
var id=document.getElementById('txt_id').value;
var chinese=document.getElementById('txt_chinese').value;
$.ajax(
{
type : "POST",
async: false,
url :"ajax/ajax_add_form.php",
data :
{
english:english,
chinese:chinese,
id:id
}
}).done(
function(html)
{
alert(html);
});
}
</script>
</head>
<body>
<input type='text' name='txt_id' id='txt_id' value='' /><br>
<input type='text' name='txt_english' id='txt_english' value='' />
<input type='text' name='txt_chinese' id='txt_chinese' value='' />
<button type="button" >Click Me!</button>
</body>
</html>
PHP Code: ajax/ajax_add_form.php
<?php
header("Content-type: text/html; charset=utf-8");
include("../config.php");
extract($_REQUEST);
$sql=oci_parse($conn,"insert into test(id,english,chinese)values('".$id."','".$english."','".$chinese."')");
oci_execute($sql);
echo "success";
?>
解决方案 .ajax(
{
type : "POST",
async: false,
url :"ajax/ajax_add_form.php",
data :
{
english:english,
chinese:chinese,
id:id
}
}).done(
function(html)
{
alert(html);
});
}
</script>
</head>
<body>
<input type='text' name='txt_id' id='txt_id' value='' /><br>
<input type='text' name='txt_english' id='txt_english' value='' />
<input type='text' name='txt_chinese' id='txt_chinese' value='' />
<button type="button" >Click Me!</button>
</body>
</html>
PHP Code: ajax/ajax_add_form.php
<?php
header("Content-type: text/html; charset=utf-8");
include("../config.php");
extract(
_REQUEST);
sql=oci_parse(
这篇关于如何使用PHP在oracle 11G数据库中存储/检索中文字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!