This code is for the mysql_, I want to change it to mysqli_.
Here is my code:
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
The connection string is:
$con = mysqli_connect(host,user,password,database) or die('Unable to Connect');
Related
I am fetching data with mysql_fetch_assoc() the string is Arabic it's echoing like this ?????
I tried encoding but not worked.
$dbc = mysql_connect("localhost", "root", "", "tedmon") or die("Error 3: " . mysql_error());
mysql_query("SET NAMES utf8");
mysql_query("SET character-set utf8");
$sqlForStudent = "SELECT `MONITORING_PROVINCE`,count(*) FROM `student_interview` group by `MONITORING_PROVINCE`";
$sqlForadmin = "SELECT `pro`,count(*) FROM `ttc_admin_interview` group by `pro`";
$sqlForteacherev = "SELECT `pro`,count(*) FROM `ttc_teachers_evaluation` group by `pro`";
$sqlForteacherint = "SELECT `pro`,count(*) FROM `ttc_teachers_interview` group by `pro`";
$studentset = mysql_query($sqlForStudent);
$adminset = mysql_query($sqlForadmin);
$teacherevset = mysql_query($sqlForteacherev);
$teacherintset = mysql_query($sqlForteacherint);
while($teacherevres = mysql_fetch_array($teacherevset)){
echo $teacherevres['pro'];
}
Change from
mysql_query("SET NAMES utf8");
mysql_query("SET character-set utf8");
To
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
Make sure you have added charset in head your page.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Note mysql extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0
first of all , I connected two database -mssql & mysql- .
global $link,$link_voip;
$link = mssql_connect('A', 'B', 'C');
mssql_select_db('D', $link);
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
$link_voip = mysql_connect('E','F','G') or die("err");
mysql_query("SET NAMES 'utf8'", $link_voip);
mysql_query("SET CHARACTER SET 'utf8'", $link_voip);
mysql_query("SET character_set_connection = 'utf8'", $link_voip);
mysql_select_db('voip', $link_voip);
I want to update a row on mysql database with mssql's information:
I get information correctly , but mysql database cannot insert utf-8 (persian language).
I'm working with phpmyadmin ,I used to try:1- change collation to utf_general_ci 2- add
mysql_query("SET NAMES 'utf8'", $link_voip);
mysql_query("SET CHARACTER SET 'utf8'", $link_voip);
before query.
3-add N before variable that may be changed.
$q="UPDATE cc_card SET firstname=N'$fname' , lastname=N'$lname',phone='$phone',credit='$credit'
WHERE id='$id'";
but still it doesn't work.
1- in mssql :
1-1. check table type is nvarchar
1-2. convert to varbinary (CONVERT(varbinary(MAX),tblname)
1-3. use bin2hex 1-3. use chr(hexdec$varibale)
1-5. use iconv
2- in mysql:
use N before variable for update/insert in database
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
I'm currently trying to save a japanese-character string with MySQL in PHP. The characters are saved as questionmarks. This is my query:
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
$result = mysql_query("INSERT INTO battles (basic_words) VALUES ('".mysql_real_escape_string($basic_words)."'");
The string "$basic_words" definitely contains japanese characters but they are not saved. The coalition for the row "basic_words" is utf8_general_ci
php mysql query encoding problem suggests
$db_con= mysql_connect('localhost', 'user', 'password');
if( function_exists('mysql_set_charset') ){
mysql_set_charset('utf8', $db_con);
}else{
mysql_query("SET NAMES 'utf8'", $db_con);
}
Also Check http://php.net/manual/en/function.mysql-set-charset.php
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...");