C++ connect to website database

So I am playing around and seeing if I can code something to connect to a web host database so I can essentially use it as a storage container. I know you can code something up to connect to mySQL locally. But I am curious how I can go about doing this with a web host MySQL (my Godaddy site). I just started with trying to connect to databases so I'm a little lost on the connecting part. I could host a MySQL and use it for local and remote, but I wanted to see if I could use the one hosted provided by godaddy, and avoid having to host one myself. If that makes sense? Is there a good tutorial anywhere for this that goes into good detail? 😂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <windows.h>
#include <mysql.h>     // using the MySQL header files.
using namespace std;

int main(){
MYSQL * conn;
conn = mysql_init(0);
conn = mysql_real_connect(conn,"tcp://sitename.com:1234", "username", "password", "database name", 0, NULL, 0);
if(conn)
  cout << "connected.";
else
  cout << "Not connected.";

return 0;
}
Last edited on
Actually the database has nothing to do with a website.
The website uses the database. So what are you trying to accomplish?
I could host a MySQL and use it for remote, but I wanted to see if I could use a website that I have that uses MySQL so that I don't have to host
I'm somewhat confused by your terminology and can't really understand what it is you're trying to do. However, while there may well be other ways, glancing around the Web there seems an almost universal usage of MySQL Connector for C++/MySQL connectivity, per the links below. (or are these the ones which you think go into too much detail?).

From looking at them quickly they seem very useful and quite user-friendly, although there is indeed a lot of information.

https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-examples-connecting.html

https://dev.mysql.com/doc/connector-cpp/8.0/en/

https://dev.mysql.com/doc/connector-cpp/8.0/en/connector-cpp-introduction.html

Not even sure if this is the sort of thing you're hoping for, but it seems a good place to start at least.
Right now i'm just trying to establish a connection. Ultimately I am trying to just push info to tables and pull and view it. I cant get it to connect and I don't know if the host provider (Godaddy.com) even allows this? (Dont know much about websites save for the basics) But I think it should work, meaning I have the settings right, i'm just not doing it right.

No I wasn't using those headers but Ill give them a try. I was using a older connector, these that I was finding
https://drive.google.com/file/d/1u8yrXuk54lOUmwJvXt8BRBPNuMUAlAje/view

They are an older version from MySQL I think. I assume I am providing the correct username, password and database name, but I am not 100% on the connection. This is probably a really basic question, but just going off of these examples from https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-examples-connecting.html

1
2
3
4
5
6
7
8
9
10
11
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;

driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
/*right here, this IP thats being provided, 
is it better to provide the IP or the site name? Shouldn't matter right? 
Should I be using the IP that's provided from the host cPanel? The port in phpMyAdmin
says 3306 at the top so I assume that parts right*/

delete con;


Im going to give this connector a go though, looks less complicated. Thanks
PS: Also sorry if the initial post was confusing, I care nothing about the site itself. Just trying to connect to the database.
Last edited on
Thinking about your question, and trying to understand what you're doing, I think I have a vague notion of what you're attempting to do, but (as you noted) you're not sure if your host provider will allow it (and I also have no idea what sort of hosting you have there).

However, FYI, in case you find it useful, the following link shows how you would set up MySQL to grant access for a remote user (assuming you have sufficient privileges to MySQL). The link is on Rackspace, but it would be the same deal on GoDaddy too, if you have the privileges.

If you're unable to set up a user for remote access like this then I don't think anything else you do will work anyway.

∙ https://support.rackspace.com/how-to/mysql-connect-to-your-database-remotely/

You may also find the following useful; it's not entirely dissimilar, but may be helpful if you're using IPv6 addresses:

∙ https://dev.mysql.com/doc/refman/5.5/en/ipv6-remote-connections.html

Good luck; hopefully in conjunction with using the MySQL Connector for C++ you can get it working.
Last edited on
Topic archived. No new replies allowed.