Accessing local MySQL from Xcode (cocoa) and macos

I've seen a ton of tutorials of accessing MySQL for IOS apps using PHP, but that is not what I want to do. I have some C programs where i use the MySQL API to access a local MySQL database that work fine, but I want to port them into an app using Cocoa so I can have can build a GUI around them.


I'm using Xcode 10, Swift 4.2. My first attempt was using Cocoapods (mysqlswiftnative, mysqldriverswift), but I get lots of errors when I compile a "Hello World" app that worked fine before adding the pods. They no longer seem to be supported in Github as I've seen similar type errors, but nobody has responded for months. My search of MySQL forums has not turned up anything, either.


I guess I could just create some object files in C which contain things I want to do, but that sounds like a lot of extra work. Surely there has to be some way to pass SQL statements into MySQL from Swift and access the results much the same way it works in C without having to go the PHP route IOS apps use.


Any suggestions would be helpful.


Thanks,


Tim.

>without having to go the PHP route IOS apps use.


...but....the iOS 'route' has it's roots in the macOS/OS X route, where PHP/mySQL pre-dates iOS. Don't re-invent a re-invented wheel 😉


I don't believe webview is officially deprecated on macOS, yet, so...use it or wkwebview w/php and live large.

Did you look for some other library? I can do a Google search easily enough and see 5 on the first page. One of those is that one abandonned project that you tried. Such is the nature of both open source software and Swift. Three years old may as well be six feet under. If you must use that library, you could fork it and update it for modern Swift. Or you could use one of the other ones. Or you could use any of the Objective-C versions that have been written over the past couple of decades. Or I guess you could probably even use the C version.

Hello Tim,

did you find a solution for your problem? I'm looking for the same and I did not find a working solution. I develop a backend software with swift-kuery actually but you have to create lots of code which could be generate. So I like to write a code generator. I tried to use the kuery libraries but I did not find a way to use them in my cocoa project with that package manager. All I found were answers how to connect iOS apps with MySQL but all these authors didn't understand the php solution. The php solution is a webservice based client - server solution but I want and I think that was your goal, too, a server - server solution where the php part is written in Swift. So did you find a solution to access MySQL from a cocoa application even in Swift or Objective-C?

A hint would be very helpfull.


Jens

I think you need to review how client/server architecture works. What you ask is impossible.

If you want to connect to MySQL database directly from your app, consider the library OHMySQL. It supports iOS, macOS and Mac Catalyst.

Enjoy!

The overwhelmingly popular library to do this is just https://github.com/groue/GRDB.swift - everyone uses it

It's the library used in the native apps of every large corp we work for. It's dead easy to use and is indeed in combo with mysql the very best on-phone database system.

Accessing local MySQL from Xcode (cocoa) and macos
 
 
Q