Connecting to External mysql DB (2018)

Hi - I am new to Wix and I’m trying to connect to an external mysql DB. I’ve seen people say that it was not possible in the past but I’ve read of people using NPM mysql. I’m wondering what is the best/easiest way to do this in late 2018.

I tried to get the sample code from here mysql - npm working on a backend web module but get the error ‘require’ is not defined.

Any advice is appreciated! Thanks

this has come up before. Search this forum on “require”. Basically, if I remember correctly, require is flagged as an error in the editor (red dot), but will run in Publish Mode. If you want to avoid this, replace “require” with import. There are enough examples around in the Tics and Tricks section. Good luck.
And BTW: keep me updated on the progress. Very interested to know how far you get, what you needed to (re)develop (like data binding, if you use Wix Code Input elements).

Thanks for the reply! I’ll take a look at older posts. Sounds like I’m on the right track with npm mysql

Update: I was able to get the “require” mysql to work and I can successfully connect to my DB. However, when I try to pass data from the DB into the front end from the back end I get “Uncaught (in promise) Error: Bad Gateway”. I’ve mimicked what I want to do locally with Node.js and it works so I’m wondering if it just something with the Wix environment. Do you have any ideas?

Have you been able to solve require problem?

yes, I was able to figure it out.

can you help me to get connected and write some data to mysql database. A sample code will be very helpful

i need this too…any luck??

@jakesheets22 yea, check out this thread I posted. I posted the solution that worked for me in it. https://www.wix.com/code/home/forum/community-discussion/best-way-to-retrieve-data-from-an-external-mysql-db

@polignano_francis great help – quick reply … thank you !!!

@jakesheets22 no problem! let me know if that works for you …

@jakesheets22 Have you been able to fix your problem?

Hi tpolig01,

I’m starting to use Wix to create a site, and one of the functions we chose it is because it allows to connect with an external MySQL DB. We have one, but weren´t able to connect to it.

We connect to it locally and over Internet, via php, via vb.net and so on, but no way to do it via Wix.

We’ve tried to add the Database as a external collection, but doesn’t work. Have open a ticket with Wix a few days ago, but still haven’t got a response. It seems that adding npm mysql module is the first step, but don’t know wich are the next ones.I’ve read all your posts, and it seems you were in a similar situation, and solved it, but I can’t see how you do it.

So If you could gave me some basic instructions about how to call the BackEnd .jsw module from the Front End to get the MySQL data in my page, I’ll be very gratefull. Thank you anyway for your posted code.

l

Corvid lets you connect your site to an external collection and then work with that collection in your site just as you would with our built in collections. See Corvid: Working with External Database Collections and Corvid: Adding and Deleting an External Database Collection .

Take a look at the docs and come back here to ask questions and share your experiences.

This is an old thread and will be closed.