API to connect to my MySQL Database Remotely - php

apparently my hosting provider does not support Remote MySQL Usage as it says in its Knowledge Base even though i bought a premium package
remote MySQL connections are disabled for security and performance reasons. You can only connect to MySQL from your PHP scripts hosted on our servers.
is there any way i can make an API so that i can connect to my MySQL Remotely ?. i need to use the Database in my Host Account as a source of information for my Android Application. thanks

You should look into using something like a HTTP Tunnel.
This post outlines a method of doing this for Android.
Basically you connect through this tunnel which is placed on your server, and can the communicate with the server as if you were localhost.
SSH is also another option, although you'll need remote SSH access enabled by your host. That's normally something you'll have to specifically request for them to enable.
You would then create an SSH tunnel using a technique like this and then use that as your connection for your database. Once you've initiated the connection you would then query it as normal.

There are possibilities here.
Your hosting provider may have allowed access of the database only
on certain IP(s) on certain PORTS. In this case, you cannot access
the database even if you write API's because the connection is not
open to the IP/PORT through which you are accessing through.
The database admin can also block access to certain table(s) or
database(s) for certain users.

Related

MySQL database access without hostname via PHP

I'm doing this for a couple of years now but I haven't faced anything like this. I'm renting a webserver which has MySQL storage. For security reasons the hosting company refused to give me a host name to connect to the MySQL server from a php script. The reason was that there is an IP filter on he server and one can only connect to it with a whitelisted ip. Is there any solution for this situation like a server sided proxy? Also I do have access to the MySQL server via phpMyadmin.
I did some research and I've found that Navicat has proxy support. Altough it's not free.
Based on your description, it sounds like you have a server with MySQL, PHP and phpMyAdmin all running on the same server. If that's the case then typically the hostname for MySQL will be "localhost", possibly with a port or other code added. It is quite common for web hosting companies to not allow remote MySQL access, though the good ones will have it off by default and let you turn it on either for specific IPs (best) or for "everywhere".
When you are logged into phpMyAdmin, take a look at the very top of the main window and you should see something like Server: localhost or Server: www.example.com:3306 - that is your hostname for any MySQL access, provided the PHP code is running on the same server as phpMyAdmin.
If you actually need to run a program on a different server and access that MySQL database then you are probably out of luck.

SSH Tunneling and Android

I am working on a project for an app that allows Android to remotely connect to an MySQL Database using a PHP API.
Users have requested that the app should support SSH Tunneling which I have been looking into but I have a few concerns regarding this.
How the app works is the API runs on my web server (the user has the option to install on there own servers but most don't) so Android sends a post to the PHP API, and then PHP directly connect to a MySQL Host that was sent in the post message from android, this is all working fine.
However, if I want to support SSH tunneling, my understanding is that my Android app would still post to my PHP API, but instruct to open an SSH tunnel, for example forwarding local port 3307 to remote host example.com on port 3306. Then PHP would connect to MySQL via 127.0.0.1 on port 3307.
This is fine, except if another user then decides to use port 3307 at the same time another user is doing a tunnel the second user would clash as the first user already has 3307 open so they would need to pick a new port.
I thought that then the best work around for this would be the API has a pool of sockets that it can use and picks one that is free and connects via that local port via the specified remote port that android sent. E.g. the API will for example pick local port 5000 and forward to 3306.
My worry here is that although this would work, there is a potential risk that two users could make a request at the same time, and the API picks the same port number to use as a local port, e.g. 5000, as this port is technically free but then one user would successfully connect, and the second user would end up connecting to the first users servers, and hopefully fail to authenticate but still, potential risk here.
Am I thinking of this the correct way, or is there a better way, or should I only support the SSH tunneling option if the user is running the API from there own web server instead of mine so there would be no risk of clashing with another unrelated user.

Remotely managing a mysql database as a limited user

I have a mysql database at my web hosting service, which I would like to access from a C# application on my local computer.
Due to account restrictions, I can't enable remote connections on the database server.
I would like some suggestions on how to execute CRUD operations on the database remotely i.e. from my localhost or any other place which is not on the server itself. The first idea that popped in to my head was to create a PHP REST API on the server and let it do the database work.
Is that the way to go? If so, is there anything similar created already, or do I need to make it from scratch? Perhaps you have other ideas?

How to connect VB.NET to Web Host

Basically, I want to create an application like this:YOUTUBE
I want to create an application that when I add some information from my web host (either PHP or MYSQL) VB.NET will read it.
From your website you'll need to insert the data into your MySQL database.
The problem with using the database provided by your web host is that the chances are, due to 'Security Reasons' the will have disabled external access.
This means that any files outside of your web server (your sites root/sub directory) will not be able to access the data. So, while your website will be able to connect without a problem, your program will not.
Some hosts give its customers the opportunity to add an IP address to a white list which enables them to bypass their security system. However, most will not give you this option.
My suggestion is that you either rent a VPS where you can run both the WebServer and Your MySQL database (and PHPMyAdmin) from or Set Up A MySQL database on your PC (its not that difficult just read the manual and youll be fine). If you had a VPS then you would no longer need your pre hosted webserver as you could run your own. You would need to point your domain name to your VPS webserver. It will act just like any other.
By running your own MySQL Databse you are given the option to enable remote access. This means that any external entity with the correct details will be able to connect.
If you cant get a VPS or don't want to run your own server or rent a server that allows for external access. Check out db4free.net .They provide you with a free MySQL Database with external access for Developers to test out their systems. They are not ultra fast so that's something you may want to be aware of. Another thing is that your data that's held can be removed at any time. The servers are not there to be used permanently just for testing.
So how do I connect to it through VB???
Good Question! To establish a connection, I suggest you use MySQL.Data library provided my DevMySQL themselves and import it into your program. Done so by Imports MySQL.Data.MySQLClient. This is written by them to work with their databases. Yes you can connect using some of the functions already in VB but in my opinion they don't work as efficiently. You'll need to download the MySQLConnector to connect as well.
Hopefully That Answers Your Questions. Any Problems Just Comment below!
Regards
Joe

Synchronise Database between servers via php

I'm needing to synchronise two mysql databases between different servers on a regular basis, by a client-initiated interface. I've been doing it by remote MYSQL connection, and adding the IP of the servers to the whitelist for MYSQL remote connections. Problem is however, that the client has a dynamic IP, so as soon as it changes they can no longer sync.
So I'm trying to find an alternative way of synchronising the two databases via some sort of secure php script.
edit: I should make this a bit clearer. I've got a server (WAMP) running on a PC (Win7) the database of which I need to synchronize (both ways) to an online server. I've been doing it via remote MySQL connect, which I'd like to avoid because of dynamic IPs, and also because the local WAMP server connects to different internet connections (being a laptop) and needs to not be restricted to one IP.
However you want to synchronize the databases (replication, a PHP script, etc.), the best way to secure it would be to either use an IPSec/VPN or SSH tunnel to encrypt all the communication between the two servers. Then you'd just open a regular mysql or http connection through the tunnel.
Using either method, you'll have access to a variety of authentication modes. So you could use a pre-shared key or username/password authentication or both.
You can use an SSH client like PuTTY to initiate an SSH tunnel on a Windows systems. Or if you google IPSec and XAuth, you should be able to find some guides on how to set up an authenticated IPSec VPN.

Categories