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.
usingnamespace 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;
}
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.
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.
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.
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.