Cannot Connect to Mssql database using PHP on shared Namecheap server - php

I am trying to connect to a mssql database hosted on a different website than the one I am connecting from. The basic syntax of my code is
$db = mssql_connect($server, $username, $password);
and I get the error
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: *ip* in *filename* on line 41
I am using a Namecheap shared hosting account to host my site. I had to go into the php config to enable the mssql module.
According to this Namecheap support page
Remote MySQL connection is disabled on our shared servers due to security reasons
So my question is is my error due specifically to my site being on shared servers? Is that quote referring to connections going out from the host, or does it mean connections coming in? I would think that it wouldn't let me use the Mssql module at all on the shared servers if it was literally impossible to use it.

I suspect that the connection issue is due to NameCheap's block of mysql. You can check the logs MySql log man page for more information about your MySql errors. If they are blocking it, there's no amount of PHP code you can write to overcome this. NameCheap has great customer support, you can do a live chat to ask them.

Related

API to connect to my MySQL Database Remotely

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.

Cannot access MySQL database from my website, but can access via browser?

I'm trying to hook up my website to my MySQL database on my new webhost, and I'm running into a few issues I can't resolve.
If I navigate to mywebsite.com/phpmyadmin/, I'm presented with an HTTP authorization, and upon successful entry of that, my PHPMyAdmin login page, where I can log-in as my user and see my databases. Yet, if I try to connect via PHP through my website, I receive the error:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mywebsite.com/phpmyadmin' (11)
My connection info is:
$this->dbh = new PDO('mysql:host=mywebsite.com/phpmyadmin;dbname=mydb;charset=utf8','me','myPassword');
I'm running LAMP on Ubuntu 14. Is there any particular reason this is failing?
PHPMyAdmin is a database client application, not a database server.
You need to provide connection information to your database server (which will probably be localhost)
You need to connect to the mysql server rather than the phpMyAdmin interface (won't work).
In this case it's you will use localhost (Really). Why? because localhost just points to the server's local IP. You can also point it to any hostname which points to the server's IP so it knows which server to connect to! :)

How to connect to WordPress database remotely?

I have a WordPress website, which is not done by me, all I need to do is connect to its database remotely and query some results from its database. The point is that I don't know anything about WordPress, and I saw that the database information are written inside the wp-config.php file, when I opened it, there was the username and password, but the host name was this:
define('DB_HOST', 'localhost');
Which seems a bit curious to me. The website uses cPanel X from GoDaddy, and when I logged in there and opened phpMyAdmin, it had these information under database server part:
Server: Localhost via UNIX socket
So, I really don't know how to remotely connect to the database and query things, because host name says localhost. I'm used to ASP.NET MVC, and where I specify the host name to be the actual server ip or hostname of the database server. Any idea how should I proceed?
This is probably a better question for superuser as it's technically a hosting related question. That being said, you would need to contact GoDaddy and find out if they even allow remote MySQL connections on their servers. Most hosting companies disable external connections to the MySQL server on port 3306, but if you portscan your domain name/IP and see 3306 open then you can probably remote connect to it. Just use the domain name/IP of your site as the host, and pull the user/pass/db name from the config file.
You can do this by using command line.
GRANT ALL ON wpdb.* TO wpuser#`192.168.2.25` IDENTIFIED BY `Pa55w0rd!`;
Check here for a detailed tutorial.

How do I connect Dreamweaver to a MySQL database on 1and1?

I am hosting a site on 1and1, and having trouble connecting to a MySQL database.
I am very new to MySQL and PHP, so I'm not sure I did this right.
Under my domain,
choose Web Space>MySQL Administration
(get taken to PHPMyAdmin)
New Database
Once DB has finished setup,
use "host", "username" and "password" given by 1and1 to connect Dreamweaver.
I tried doing this, but Dreamweaver gives me an "Unknown error", which doesn't help at all, as it doesn't even give an error *code.
It's pretty common on shared hosting to allow db connections only from apps running on their servers. Connections from other clients are blocked/rejected.
If you are able to connect your Dreamweaver to a local (on your machine) MySQL server, then it's probably the case that 1and1 is blocking your remote access.
1and1 do not permit external connections to the databases
You should still be fine to connect with dreamweaver. That error you get is usually because the publishing URL (usually the same as default www.domainnamehere.com) hasn't been configured in DW under the Testing Server section yet.

Connecting remote server mysql database to localhost

How can I connect my localhost PHP files to my remote server MYSQL database?
For example: if we download WordPress, and it gives us an option to login, so that our login credentials are saved with WordPress but still our localhost files connects to that database.
How do I do that?
Thanks.
If you want your PHP code to connect to a remote MySQL database, you just have to specify that remote host when calling the function that connects to MySQL.
For example, when calling mysql_connect(), don't specify localhost as first parameter -- but your real remote host.
Same with mysqli::__construct() or PDO, of course.
A couple of notes :
Your remote host must accept connections to MySQL (think about the firewall)
Your remote MySQL database server must accept connections from non-localhost
Sending queries, and fetching results, to/from a far away server will be a lot slower than doing so on localhost !
mysql_connect(SQL_IP, SQL_NAME, SQL_PASS);
Well when you install Wordpress set the host to be the IP of your remote server. If this isn't what you're looking for, please reword your question. If you're not using word press, check ou the PHP documentation for mysql_connect. The first parameter is the host. Enter the IP or hostname of your remote server here. And then follow that with your username and password.
mysql_connect('remote-host', 'myuser', 'mypassword');
Note: Some hosts do not allow remote connections to MySQL. Check your remote server doesn't have 3306 firewalled or only instructed MySQL to bind it to 127.0.0.1.

Categories