How can i store Hindi data in Mysql?
I want to code using zend.
I created 1 table in Mysql, I set collation as utf8_general_ci.
You should probably use UTF-16 rather than UTF-8. See: http://forums.mysql.com/read.php?103,86499,86910
As you are coding using ZEND PHP Framework, just before the SQL Query for insert/select add the 2 lines for Setting NAMES & Character Set:
$dbhost = 'xx.xx.xx.xx';
$dbuser = 'xyz';
$dbpass = 'xxxxxx';
$dbname = 'yyyy';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
mysql_query("SET NAMES utf8");
mysql_query("set characer set utf8");
$result = mysql_query("SELECT * FROM tablename etc...");
Related
I am writing an android app and i want to query a db and get the results with json_encode.
So i have this db:
CREATE DATABASE `my_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
I use utf8 because i want to store greek characters. All the tables have utf8_general_ci collation.
At last i have this php service that i use to query my db.
<?php
$host = "localhost";
$username = "root";
$password = "password";
$dbname = "my_db";
$con = mysql_connect($host,$username,$password) or die ('Error connecting to mysql');
mysql_query("SET character_set_results=utf8", $con);
mysql_query("SET NAMES 'utf8'", $con);
mysql_select_db($dbname,$con);
$query = "SELECT * from patients";
$result = mysql_query($query,$con);
while($e=mysql_fetch_assoc($result))
$output[]=$e;
print(json_encode($output));
mysql_close($con);
?>
The problem is that in the output i dont get greek characters. Instead i get this:
[{"patient_id":"2","email":"patienta#mail.com","password":"password2","firstname":"\u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3","lastname":"\u039c\u03a0\u0391\u0396\u0399\u03a9\u03a4\u0397\u03a3","birth":"1989-11-11","mobile":"6941212121","tameio":"\u039f\u0393\u0391"}]
That is right. All the chars not in ascii will be converted into UTF-8 format.
The data will be decoded correctly by json_decode.
I need to change encoding of whole database to UTF8.
I was connect to database like this before:
// MySQL connect information.
$username = "root";
$password = "";
$host = "localhost";
$database = "yac";
// Connect.
$connection = mysql_connect($host, $username, $password)
or die ("It seems this site's database isn't responding.");
mysql_select_db($database)
or
die ("It seems this site's database isn't responding.");
my database content was stored to database without mysql_query("SET NAMES UTF8"); and data was like this:
باشگاه هوانوردان جوان
now recently I connect to database like this:
$mysql_username = "root";
$mysql_password = "";
$mysql_host = "localhost";
$mysql_database = "tick5";
$connection = mysql_connect($mysql_host, $mysql_username, $mysql_password) or die ("It seems this site's database isn't responding.");
mysql_select_db($mysql_database) or die ("It seems this site's database isn't responding.");
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER_SET utf8");
and stored data is like this:
عنوان مقاله
since I use mysql_query("SET NAMES UTF8"); before INSERT queries I haven't any problem but now I need my old content and I want to change encoding and fix this.
How to do this?
NOTE : my tables Collation is utf8_unicode_ci
Try to see if this can help you. http://www.gentoo-wiki.info/TIP_Convert_latin1_to_UTF-8_in_MySQL
If you do not have a running Linux system, you can download an Ubuntu LiveCD and run it directly from the CD. http://www.ubuntu.com/download/desktop
Hey guys im trying to connect to an oracle database with php. I tried it like i do it with mysql.
How to do it like this:
$host="localhost";
$user="username";
$pass="password";
$db="database";
$link = mysql_connect($host, $user, $pass) or die ("Keine Verbindung zu der Datenbank moeglich.");
mysql_select_db($db, $link);
$sql = "SQL query goes here";
$result = mysql_query($sql);
How can i do exact this with an oracle database. I have the following connection details
sid, ip, port, username, password.
Simple script:
$DB = '//1.2.3.4:1521/XE';
$DB_USER = 'user';
$DB_PASS = 'pass';
$DB_CHAR = 'AL32UTF8';
$conn = oci_connect($DB_USER, $DB_PASS, $DB, $DB_CHAR);
$statement = oci_parse($conn, 'select 1 from dual');
oci_execute($statement);
$row = oci_fetch_array($statement, OCI_ASSOC+OCI_RETURN_NULLS);
To connect with an Oracle database, you don't use the mysql extension (since that is for MySQL). You should use PDO, with the OCI/Oracle adapter.
You'll want to use PDO to connect to Oracle here is the PHP manual page on creating a connection using PDO, the example given is for MySQL but it will work fine with Oracle. You will need to ensure the PDO:Oracle extension is installed and running on your PHP configuration.
I have a table that data was inserted in it some time ago. data included by php and character set in it was utf-8 .
mysql_query("set names utf8");
now ,I need this table in another project which all data will show on php mysql default character set.
problem : my data is persian, when I set charachter set utf-8, every things is ok, but without character set data convert to the "?????" what should I do?!
I want to import all data form old table to new table on new character set !!
Try this might help you
<?php
header('Content-Type: text/html; charset=utf-8');
?>
and then in the connection
<?php
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db($argDB, $dbLink);
mysql_query("set names 'utf8'",$dbLink);
?>
///
$SERVER = "http://localhost:8084";
$db = mysql_connect('localhost','root') or die("Not Connected");
$sldb = mysql_select_db('vifarbydata',$db);
mysql_query("set names utf8");
$sql = "SELECT * FROM `region` ";
$res = mysql_query($sql);
while($h=(mysql_fetch_array($res)))
{
$row[] = $h;
}
mysql_close($db);
/// set another character set
$SERVER = "http://localhost:8084";
$db = mysql_connect('localhost','root') or die("Not Connected");
$sldb = mysql_select_db('vifarbydata',$db);
foreach ($row as $item)
{
echo $sql = "insert into `region2` (id,name,myId) values (".$item['id'].",'".$item['name']."','".$item['myId']."') ";
mysql_query($sql);
}
#afsane, using mysqldump, you can dump the data from old_table and then import it into the new_table which has the new character encoding.
mysqldump -u user -p --no-create-info schema old_table > old_table.dump
mysql -u user -p schema new_table < old_table.dump
This will be much faster than doing a conversion via PHP.
I wrongly designed my application to have one database to each user. each user had 3 similar tables. I now want to have one database and 3 tables only; where i will use the database name in the old databases as a reference in the new system. There was another database called "users" in the old database that stored the database names. I'm done with the schema design of the new database and now left with the migration.
The trick here is that I have 3 db connections. I first connect to the users database and userinfo table, pick up the database_name in a loop, use it to connect each old db and further connect to personal, accounts and games table.
After picking up the tables, i will like to populate/join it with the new Database (DATA_ONE) and the tables whiles i append the old database_name to the new tables. Any help on this or is there a better way to do this? Thanks much
<?php
$dbhost = "localhost";
$dbname = "users";
$dbuser = "root";
$dbpass = "*****";
$conn1 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die("MySQL Error: " . mysql_error());
$conn2 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die("MySQL Error: " . mysql_error());
$conn3 = mysql_connect($dbhost, $dbuser, $dbpass, TRUE) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname,$conn1) or die("MySQL Error: " . mysql_error());
$query = "SELECT database_name FROM userinfo";
$result1 = mysql_query($query,$conn1);
while($row = mysql_fetch_array($result1, MYSQL_ASSOC))
{
$database_name =$row['database_name'];
$conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
$db = mysql_select_db($database_name ,$conn2) ;
// now, pick personal, accounts, games tables of user and populate new database and tables.
// this is where i need help.
}
?>
Why do you think you need 3 seperate database connections with the same credentials? In any mysql query you can reference tables from any database on the same instance by prefixing the table name with the database name (and a . in between). I'd suggest not using 'database_name' as an attribute name:
$databases=get_mysql('SELECT DISTINCT database FROM users.userinfo ORDER BY database');
$count_of_users=count($databases);
foreach ($databases as $user_offset=>$user) {
$uqry="INSERT INTO data_one.personal
(user, id, address, password)
SELECT '$user'
, (id*$count_of_users*$user_offset)
, address
, password
FROM ${user}.personal";
...
(assuming that 'id' is an autoincrement value which may be referenced elsewhere).