0

Is it possible to connect to a MySQL database directly from an Ionic application without an integration/api layer?

All the answers I found online suggest to create API in php or nodejs, but I would like to develop a sql client and the whole point of the application is to be able to make queries directly from the client device.

I cannot use the node mysql library from client side.

I am using Ionic 6 React.

Davide Briscese
  • 1,161
  • 8
  • 18
  • 1
    you can't direct access mysql from device... nodejs can access it because it acts as a server but as a native/hybrid platform, it can't direct access mysql... the only possible solution is to using api's.. – Mostafa Harb Jun 25 '22 at 08:03

1 Answers1

1

No, as noted by Mostafa Harb, you cannot directly access a MySQL database in the cloud from a device. You'll need to use some kind of API.

The basic flow:

  • Ionic app authenticates to the API if necessary.
  • Ionic app uses Axios or Fetch to use the API to query the cloud database.
  • The API returns the response in a format the Ionic app understands.

The good thing about Ionic is that it is mostly framework-agnostic, so you can use any API you like.

Personally, I use Drupal, which is a PHP-based CMS that has support for providing access to Ionic via REST, JSON:API, or GraphQL (or a mix of the three).

Patrick Kenny
  • 4,515
  • 7
  • 47
  • 76