Connect to remotemysql.com on my website? - php

I want to connect a database on remotemysql.com too my website (ddu.nu/3/weatherstation). When i try to run the connection to the database on the website the connection fails. But when i try the exact same code on the localhsot the connection is created. Here is the code that i am using.
$connect = mysqli_connect("remotemysql.com:3306", "dbuser", "dbpass", "dbname");
if(!$connect ) {
die('Connection failed: ' . mysqli_error());
}
echo 'Connected successfully';
The website doesn't give any error.
Here is the website
And here is the localhost
My quetion is what I need to do in order for the real website to function.

You should try to disable ssl or the ssl have to have ssl cert, mine is work pefectly with ssl disable:
String dbURL = "jdbc:mysql://remotemysql.com:3306/";
Connection con = DriverManager.getConnection(dbURL + dbName + "?useSSL=false",
dbUsername,
dbPassword);

Related

Connection refused when I try to connect via php to mysql database over android app

I have a mysql database running on my local machine and I use wamp. I can login with phpmyadmin. Everything looks fine, create tables and users.
When I try to connect with php I get the message connection refused. The same when I try 127.0.0.1/connect.php in my browser. If I have a wrong user in my php file I get the message that user ist wrong.
Here my connect.php
<?php
$conn = mysqli_connect("127.0.0.1", "root", "", "users");
if ($conn) {
die('no connection: '. mysqli_connect_error());
}
echo 'connected';
mysqli_close($conn);
?
I tried everything, localhost, IP, 10.0.2.2, but nothing works. I also checked mysql settings and I read most of the posts here.
I solved the problem.
With this code it works perfect
<?php
$conn = new mysqli("127.0.0.1", "root", "", "users");
if (mysqli_connect_errno()) {
echo "no connection " . mysqli_connect_error();
}
echo 'conneted';
mysqli_close($conn);
?>

How to connect to Google Cloud SQL Database from GoDaddy Server

I am trying to connect to a sql instance on google cloud from a website that is hosted on a godaddy server.
I am getting the following error
Failed to connect to MySQL: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (110)
I have authorized the IP to my godaddy server.
Here is how I am handling my connection...
<?php
// Change this to your connection info.
$DATABASE_HOST = 'xxx.xxx.xxx.xxx';
$DATABASE_USER = 'user';
$DATABASE_PASS = 'pass';
$DATABASE_NAME = 'db';
// Try and connect using the info above.
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
// If there is an error with the connection, stop the script and display the error.
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
?>
I have been STUCK for a little while and have not seen anything on the web to help.

Filezilla Connect through PHP

I am trying to upload a file from my machine (client side) to the FileZilla server (server side) I have for storing the web page files.
When trying to connect to FileZilla through PHP I receive the following error message:
Connection failed: Connection refused
Usually, I would expect the error when the login credentials are incorrect, however, in this case, they are correct.
My question: Can you connect to FileZilla via PHP? I am sure the answer must be 'Yes' however due to the technical difficulties currently I would not be surprised otherwise.
Potentially there is an error in the formatting of the connection function.
var $host = "xx.xx.xx.xx";
var $user = "xx";
var $pass = "xx";
var $connect;
function serverConnection()
{
$conection = mysqli_connect($this->host, $this->user, $this->pass) or die
("Connection failed: " . mysqli_connect_error());
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$this->connect = $conection;
}
return $this->connect;
}
The goal is to be able to upload files from a form to FileZilla, to act as users profile pictures.
Currently, you're using mysqli_connect which connects to a database server, you need to connect to an FTP server, so you should use the FTP functions. You should first connect and then login.
It should look something like this:
$server = 'myServer';
$user = 'myUsername';
$pass = 'myPassword';
$connect = ftp_connect($server) or die('Could not connect to FTP-server.');
if(ftp_login($connect, $user, $pass)) {
echo 'Connected to FTP-server.';
}

Unable to connect to MySQL database but able to connect to database server

I am trying to build a dynamic website for connecting pages with database I used the code as follows. connection with server is Ok but unable to select database. data base name, user id, password, ip of host all gave but not working. please help....
define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', '');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
else {
echo 'connected to server..................'; }
$db_selected = mysql_select_db($DB_NAME, $link);
if ($db_selected) {
print "Database Found";
}
else {
print "Database NOT Found";
}
Mysql has been deprecated and will eventually be removed. Consider using PDO or MySqli.
Here is a link to the PHP documentation page for making connections to a database using MySqli.
http://php.net/manual/en/mysqli.quickstart.connections.php
If you follow the instructions carefully you 'should' be able to connect. If not, perhaps you can post the error message you receive.
Try to give proper credential to connect to mysql server. mysqli_connect("localhost","root","password","db_name");

mssql_connect() Unable to connect to server to Remote host from php hosting

I have working mssql connecting codes and them working in my another company php host but dont work when i moved new host. All codes same i dont know why connect from new host ? In new host using cpanel and php ( Hostgator ) and im looking php.ini in cpanel mssql settings looking good. my codes below under.
$usernameb ="myuser";
$passwordb = "mypass";
$databaseb = "mydb";
$host ="myhostip"
$connection = mssql_connect($host, $usernameb, $passwordb);
if (!$connection) { die('Not connected : ' . mssql_get_last_message());}
$db_selected = mssql_select_db($databaseb, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mssql_get_last_message());
} else{
}
And gives that error on my new hosting
Warning: mssql_connect(): Unable to connect to server: ip here in
Any idea ?

Categories