Link to home
Start Free TrialLog in
Avatar of patrik20
patrik20

asked on

create two tables, default collation is "latin1_swedish_ci” and other table with collation “utf8 COLLATE utf8_persian_ci”

Hi

I try to create two tables, the first one has the default collation "latin1_swedish_ci”  and the other table should has collation “utf8 COLLATE utf8_persian_ci”,  and I will insert Persian text into the second table.
But my script creates both tables with the default collation "latin1_swedish_ci” , and put ???? in the second table.

Here is the code. What am I missing / doing wrong?

<?
include ("serverdata.php");

$con = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbName, $con);
$query1="
CREATE TABLE admin (
  id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  username VARCHAR( 11 ) NOT NULL ,
  password VARCHAR( 11 ) NOT NULL ,
  email VARCHAR( 50 ) NOT NULL
) TYPE=MyISAM";

$query2="INSERT INTO admin VALUES (1, 'över', 'för titel1 på svenska', 'webb@hotmail.com');";

$query3="
CREATE TABLE subjectir (
  id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  title1f TEXT( 200 ) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL ,
  title2f TEXT( 200 ) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL ,
  textf TEXT( 1500 ) CHARACTER SET utf8 COLLATE utf8_persian_ci NOT NULL  
) TYPE=MyISAM";

$query4="INSERT INTO subjectir VALUES (1, ' some persian text, .', ' some persian text ', ' some persian text ');";

$result1 = mysql_db_query($dbName,$query1) or die('Error1: creating admin table');
$result2 = mysql_db_query($dbName,$query2) or die('Error2: inserting in admin table');
$result3 = mysql_db_query($dbName,$query3) or die('Error3: creating subjectir table');
$result4 = mysql_db_query($dbName,$query4) or die('Error4: inserting in subjectir table');

echo "<FONT SIZE=4><b>All tables created successfully</b></FONT><BR><BR>";
?>
Avatar of QPR
QPR
Flag of New Zealand image

As far as I know, you have defined the collation for that column not the table.
Therefore your table may have the default collation but your text columns are utf8_persian_ci
That is if tables actually have collation at all?
As far as I'm aware collation is defined either at the server, database or column levels.
Looking at the code you posted it seems that you have achieved what you want to.
If you have access to the sql server, open the 2nd table in design view and click on one of the text columns.... in the properties for that column you will see the collation. If it says database default then it didn't work.
Avatar of patrik20
patrik20

ASKER

you are right, but how should I make it to put persian text into columns?
yes 3 columns in table2 have collation utf8_persian_ci.
I make the first table in default collation latin1_swedish_ci and  then I put Swedish text into those columns.
And I have the second table with column collation “utf8 COLLATE utf8_persian_ci”.  

Is it possible to insert "Persian text" Into those second table?
ASKER CERTIFIED SOLUTION
Avatar of QPR
QPR
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't know about persian, but for chinese collation you actually have to change the database collation to be Chinese, not just the column. I don't know what impact this will ahve if you have swedish and persian - you would have to test.
I run the line but got error:
Fatal error: Undefined class name 'from' in /home/bc9ba1a/public_html/test.php on line
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial