Accessing Mysql on a server

I’m only asking about this because it’s not really well covered in the language reference.

  1. can I access MySQL databases with real basic - the database is whatever wordpress uses (we are going to create some extra tables and store data in our wordpress database) without using a plugin. I had professional and now using Xolo.

how can I do this so I don’t need to change the code for MAC and Windows?

What do I define my database as?

dim db as new ?

Cheers,
Sean

dim db as new MySQLCommunityServer
db.Host=“yourHostAddress”
db.UserName=“yourUserName”
db.Password=“yourPassword”
db.DatabaseName=“yourDatabaseName”

Then remember to set up the connection with UTF-8
if db.Connect then db.SQLExecute “SET NAMES ‘utf8’”

And when retrieving strings to define them to UTF-8 : dim myString as string=rs.field(“myField”).stringValue.defineEconding(encodings.utf8)

Since Xojo loose the string encoding definition

I don’t’ recommend trying to learn from the Language Reference.

You probably ought to start with the User Guide and then use the Language Reference to get the details once you understand the basic concepts.

User Guide Book 3: Framework has a Database chapter with a MySQL topic that shows you how to connect and do a few other things.

And I also did a video that shows how to connect to MySQL with Real Studio that you may find useful:

Connecting to MySQL

What the guide user forgets to mention is that the plugin produces a string without encoding (unlike, for example, that for SqlLite)
The string in xojo are in UTF-8, so there may be problems if you do not force the encoding by reading the results of the plugin.

Apparently there is no solution to this perennial problem. And this despite mysql is now installed with the UTF-8 encoding enabled.

[quote=12329:@Antonio Rinaldi]What the guide user forgets to mention is that the plugin produces a string without encoding (unlike, for example, that for SqlLite)
The string in xojo are in UTF-8, so there may be problems if you do not force the encoding by reading the results of the plugin.

Apparently there is no solution to this perennial problem. And this despite mysql is now installed with the UTF-8 encoding enabled.[/quote]
Not really forgotten since I didn’t realize this was an issue.

For now, I’ve updated the MySQLCommunityServer page in the Language Reference with this information about encodings.

The MySQL plugin that we ship with Xojo is open-source. In fact, the complete source is included with Xojo (in Database Plugin Resources/MySQL/source). If any enterprising folks see an obvious way this can be addressed, please create a Feedback case with your suggestions.

[quote=12333:@Paul Lefebvre]Not really forgotten since I didn’t realize this was an issue.

For now, I’ve updated the MySQLCommunityServer page in the Language Reference with this information about encodings.

The MySQL plugin that we ship with Xojo is open-source. In fact, the complete source is included with Xojo (in Database Plugin Resources/MySQL/source). If any enterprising folks see an obvious way this can be addressed, please create a Feedback case with your suggestions.[/quote]

Is an issue al long concatenating an UTF string (default in xojo) with a nil encoded string gives you a nil encoded string. And if you write non ascii chars you will note the issue.

The feedback relative to this is :feedback://showreport?report_id=18906

I took a quick look at the source of the plugin and I’ve seen that is not made any “forcing” to the encoding from which the nil encoding.
But I also saw that for the memory cursor is done so in any way you can.

[quote=12257:@Antonio Rinaldi]Then remember to set up the connection with UTF-8
if db.Connect then db.SQLExecute “SET NAMES ‘utf8’”

And when retrieving strings to define them to UTF-8 : dim myString as string=rs.field(“myField”).stringValue.defineEconding(encodings.utf8)

Since Xojo loose the string encoding definition[/quote]

This saved my day, thank you @Antonio Rinaldi

[quote=12257:@Antonio Rinaldi]dim db as new MySQLCommunityServer
db.Host=“yourHostAddress”
db.UserName=“yourUserName”
db.Password=“yourPassword”
db.DatabaseName=“yourDatabaseName”

Then remember to set up the connection with UTF-8
if db.Connect then db.SQLExecute “SET NAMES ‘utf8’”

And when retrieving strings to define them to UTF-8 : dim myString as string=rs.field(“myField”).stringValue.defineEconding(encodings.utf8)

Since Xojo loose the string encoding definition[/quote]

Great! It work!
Thanks, Antonio :slight_smile: