Question:
vb insert Unicode text into mysql database?
gerald m
2010-03-23 04:38:47 UTC
Hi,

I am trying to insert unicode (ex. Russian characters ) text into a mysql database. The content got replaced as question marks (????) after inserting into db.

Programming Language : Visual Basic 6.0
Mysql DB : 4.0.26
Myodbc Version: 3.51
OS: Windows XP

Following is the code:

dim sContent as string
dim cn as new ADODB.connection

sContent="русский язык"
cn.ConnectionString = "uid=root;pwd=;server=localhost;driver={MySQL ODBC 3.51 Driver};charset=utf8;"
cn.Open
cn.Execute ("use testing")
cn.Execute ("SET CHARACTER SET utf8")
cn.Execute "SET NAMES utf8"
cn.Execute ("SET SESSION collation_connection ='utf8_unicode_ci'")
cn.Execute "insert into table_name values ( '" & sContent & "')"

If i type the same insert query in any DB interfaces(PhpMyadmin/Mysql control center) the value got inserted successfully.

Please help me to sort this issue.

Thanks,
Gerald Manickam
Three answers:
ʃοχειλ
2010-03-23 04:58:29 UTC
As far as I remember, it is an issue about the older versions of MySQL. The newer version have fixed the problem of UNICODE characters. I recommend to briefly study the technical issue of the different versions and upgrade to a suitable newer version.
Peril Causing Devil
2010-03-23 04:55:51 UTC
Hi Im using VB 2008, I tried adding the Russian characters and it worked. And as a matter of fact I never mentioned the UTF set in my query. Below is the code i Used. Have a look.





Dim sqlcon As OleDbConnection = New OleDbConnection("Data Source=C:\login.mdb; Provider=Microsoft.Jet.OLEDB.4.0; User ID=Admin")

sqlcon.Open()

Dim ssql As String = "INSERT INTO login VALUES (@name,@password)"

Dim sqlcmd As OleDbCommand = New OleDbCommand(ssql, sqlcon)

sqlcmd.Parameters.AddWithValue("@name", TextBox1.Text)

sqlcmd.Parameters.AddWithValue("@password", TextBox2.Text)

sqlcmd.ExecuteNonQuery()



I COPIED THE RUSSIAN CHARACTERS TO TEXTBOX1 AND THEY WORK.
fenimore
2016-10-16 03:44:11 UTC
For eg: $call = $_post['call']; $handle = $_post['handle']; $telephone = $_post['telephone']; $effect= mysql_query("insert into table_name (identification,call,handle,telephone) values (' ', '$call', '$handle', '$telephone').mysql_error()"); if($effect) { echo "325c0ded576131ea255ad2bd38bfb2alert('effectively inserted'); } else { echo "did no longer insert"; }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...