hi guys,
i have a small problem..mysql supports arabic right..when i store data in tables it’s alright..everything works fine ?? but when i issue an sql to retrieve data..i get the arabic text as ???? marks..!! i have changed the charset of the tables and of the columns but still the same problem ??
[CODE]DROP TABLE IF EXISTS “noorbiz”.”poll_categories”;
CREATE TABLE “noorbiz”.”poll_categories” (
“category_id” tinyint(2) NOT NULL auto_increment,
“category_name” varchar(50) character set utf8 collate utf8_bin NOT NULL default ”,
PRIMARY KEY (“category_id”)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
thanx alot guys for the help..
Regards,
Noor
[CODE]<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">[/CODE]
[CODE]DROP TABLE IF EXISTS "noorbiz"."poll_categories";
CREATE TABLE "noorbiz"."poll_categories" (
"category_id" tinyint(2) NOT NULL auto_increment,
"category_name" varchar(50) character set utf8 collate utf8_bin NOT NULL default '',
PRIMARY KEY ("category_id")
) ENGINE=InnoDB DEFAULT CHARSET=utf8;[/CODE]
[CODE]mb_detect_encoding($data)[/CODE]
, it gave me ASCII..[CODE]mysql_query("set characer set cp1256");[/CODE]
[code=php]
<?php
header('content-type:text/html; charset=utf-8');
mysql_connect('localhost','root','');
mysql_select_db('noorbiz');
mysql_query("set names utf8");
list($id,$name)=mysql_fetch_row(mysql_query('SELECT * FROM poll_categories'));
echo $name;
?>
[/code]
[code=php]
CREATE TABLE IF NOT EXISTS poll_categories
(
category_id
tinyint(2) NOT NULL auto_increment,
category_name
varchar(50) character set utf8 collate utf8_bin NOT NULL default '',
PRIMARY KEY (category_id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
INSERT INTO poll_categories
(category_id
, category_name
) VALUES
(1, 'لبنان يا بلد صغير بالقلب كبير');
[/code]
<i>
</i><?php
//load plain/text data into $dataTokenCollection as a string.
$dataTokenCollection=file_get_contents(__FILE__,null,null,__COMPILER_HALT_OFFSET__);
list($sqlDataQueries,$htmlData,$htmlData2,$cssData,$htmlView,$htmlInsertDataPage,$htmlInsertDataResult)=explode('======data separator======',$dataTokenCollection);
$sqlData=explode('-- ---------sql separator----------',$sqlDataQueries);
mysql_connect('localhost','root','');
mysql_select_db('arabic_test');
mysql_set_charset('utf8');
$action=isset($_POST['action'])?$_POST['action']:(isset($_GET['action'])?$_GET['action']:'');
if($action=='Create Table')
{
mysql_query($sqlData[0]) or die(mysql_error());
mysql_query($sqlData[1]) or die(mysql_error());
mysql_query($sqlData[2]) or die(mysql_error());
//echo "Table created successfully!n<br />n<a href="{$_SERVER['PHP_SELF']}">Return to main page.</a>";
eval($htmlData2);
exit;
}
if($action=='Insert Data')
{
if(!isset($_POST['subaction']))
{
eval($htmlInsertDataPage);
}else if($_POST['subaction']=='submit'){
if(!isset($_POST[stringToSave])){echo 'No data sent!';exit;}
$str=mysql_real_escape_string($_POST[stringToSave]);
$sql="INSERT INTO <span><code>arabic_test_table1</code></span> (<span><code>id</code></span>, <span><code>arabic_text</code></span>) VALUES (NULL,'$str')";
$result=mysql_query($sql) or die(mysql_error());
$num=mysql_affected_rows();
$addEntryResult="";
if($num==1)
{
$addEntryResult.="Successfully added your post to the database!n<br />n";
}else if($num>1){
$addEntryResult.="Successfully added your <em>posts</em> to the database!n<br />n";
}else{
$addEntryResult.="An unknown error occured while trying to add your post to the database.n<br />n";
}
eval($htmlInsertDataResult);
}//else
exit;
}
if(mysql_num_rows(mysql_query("SHOW TABLES LIKE 'arabic_test_table1'"))==0)
{
eval($htmlData);//echos the results of the evaluated PHP code
}else{
$result=mysql_query('SHOW COLUMNS FROM <span><code>arabic_test_table1</code></span>');
$outTable="";
$outTable.='<table border="1"><tr>';
while($row=mysql_fetch_assoc($result))
{
$outTable.='<th>'.htmlentities($row['Field']).'</th>';
}//while
$outTable.='</tr>'; <br/>
$result=mysql_query('SELECT * FROM <span><code>arabic_test_table1</code></span>');
while($row=mysql_fetch_row($result))
{
$outTable.='<tr>';
foreach($row as $column)
{
$outTable.='<td>'.htmlentities($column,ENT_QUOTES,'UTF-8').'</td>';
}
$outTable.='</tr>';
}//while
$outTable.="</table>n";
eval($htmlView);//echos the results of the evaluated PHP code
}//else
//Everything after the halt complier will be ignored by PHP
//But in this case we will have PHP open itself in plain/text mode later to grab this data
__halt_compiler();
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-- ---------sql separator----------
CREATE TABLE IF NOT EXISTS <span><code>arabic_test_table1</code></span> (
<span><code>id</code></span> int(10) unsigned NOT NULL auto_increment,
<span><code>arabic_text</code></span> text character set utf8 NOT NULL,
PRIMARY KEY (<span><code>id</code></span>),
FULLTEXT KEY <span><code>arabic_text</code></span> (<span><code>arabic_text</code></span>)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;
-- ---------sql separator----------
INSERT INTO <span><code>arabic_test_table1</code></span> (<span><code>id</code></span>, <span><code>arabic_text</code></span>) VALUES
(1, '&#1604;&#1576;&#1606;&#1575;&#1606; &#1610;&#1575; &#1576;&#1604;&#1583; &#1589;&#1594;&#1610;&#1585; &#1576;&#1575;&#1604;&#1602;&#1604;&#1576; &#1603;&#1576;&#1610;&#1585;');
======data separator======
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ultimater's Arabic Test Database Example</title>
<link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="submit" name="action" value="Create Table" />
</form>
</body>
</html>
<?php
======data separator======
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ultimater's Arabic Test Database Example</title>
<link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
</head>
<body>
<?php
echo "Table created successfully!n<br />n<a href="{$_SERVER['PHP_SELF']}">Return to main page.</a>";
?>
</form>
</body>
</html>
<?php
======data separator======
body {
margin: 0;
padding: 1em;
font: medium arial, helvetica, sans-serif;
}
table {
border-collapse: collapse;
border: solid 2px black;
font-weight: normal;
font-size: small;
margin: 0.25em 0 0.5em 0;
}
td,th {
border: solid 1px black;
padding: 0.1em 0.25em;
}
th { background-color: #ccc; }
h2 {
/* CSS Horizontal Rule */
margin: 1em 0 0.5em 0;
border-top: solid 2px black;
padding-top: 1em;
}
li {
font-weight: bold;
font-size: large;
margin-top: 0.5em;
}
======data separator======
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ultimater's Arabic Test Database Example</title>
<link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<style type="text/css"><?php echo $cssData; ?></style>
</head>
<body>
<h2>Table <span><code>arabic_test_table1</code></span>:</h2>
<?php echo $outTable; ?>
<br />
<a href="<?php echo $_SERVER['PHP_SELF'];?>?action=Insert Data">Insert Data</a>
</body>
</html>
<?php
======data separator======
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ultimater's Arabic Test Database Example</title>
<link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<style type="text/css"><?php echo $cssData; ?></style>
</head>
<body>
<h2>Insert Data into <span><code>arabic_test_table1</code></span>:</h2>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="action" value="Insert Data" />
<input type="hidden" name="subaction" value="submit" />
<input type="text" name="stringToSave" value="" />
<input type="submit" value="Insert!" />
</form>
<?php echo "<a href="{$_SERVER['PHP_SELF']}">Return to main page.</a>"; ?>
</body>
</html>
<?php
======data separator======
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ultimater's Arabic Test Database Example</title>
<link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon"/>
<style type="text/css"><?php echo $cssData; ?></style>
</head>
<body>
<?php echo $addEntryResult; ?>
<?php echo "<a href="{$_SERVER['PHP_SELF']}">Return to main page.</a>"; ?>
</body>
</html>
<?php
arabic_test
<i>
</i><?php
//comment to preserve the whitespace after the opening PHP tag
0.1.9 — BETA 4.28