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.';
}
Related
I am working on a payroll system. Everything is working fine on localhost (xampp) but when I upload it to ionos hosting, it is loading the admin login page fine but when i enter the username & password it is giving "Connection failed: No such file or directory".
DB name: dbs4868780
and here is the code:
<?php
$conn = new mysqli('localhost', 'root', '', 'xxxxxxxxx');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
EDIT:
I tried it but it is still giving the same error.
I also tried to connect DB with PHP code provided by ionos but it is still giving "Connection failed. File or Directory not found"
Here is the php code from ionos:
<?php
$host_name = 'db5005797255.hosting-data.io';
$database = 'dbs4868780';
$user_name = 'xxxxxxxxx';
$password = 'xxxxxxxxxxxxxxxxxxxx';
$link = new mysqli($host_name, $user_name, $password, $database);
if ($link->connect_error) {
die('<p>Failed to connect to MySQL: '. $link->connect_error .'</p>');
} else {
echo '<p>Connection to MySQL server successfully established.</p>';
}
?>
See attached fake database example to get your data
I am getting SNAT Port issue. I don't know what to do I am using PHP 7.0 let me show my code
this is my db code
function db_connect() {
$server = 'P:servername'; // this may be an ip address instead
$user = 'username';
$pass = 'pasword';
$database = 'test'; // name of your database
// Create connection
$conn = mysqli_connect($server, $user, $pass, $database);
return $conn;
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
}
I am getting SNAT port issue what should I do?
Using Persistent Connections
If mysqli is used with mysqlnd, when a persistent connection is created it generates a COM_CHANGE_USER (mysql_change_user()) call on the server. This ensures that the re-authentication of the connection takes place.
https://www.php.net/manual/en/mysqlnd.persist.php
I've been trying to upload my PHP MySQL(in Dreamweaver) project to a free web-hosting site.
When I logged in, there is an error that appear in dbconn.php file.
The error is shown below:
and here's the code in my dbconn.php file:
<?php
/* php& mysqldb connection file */
$user = 1350048; //mysqlusername to db
$pass = "password"; //mysqlpassword to db
$host = "eskl.freeoda.com"; //server name or ipaddress
$dbname= 1350048; // db name in server freeoda
$dbconn= mysql_connect($host, $user, $pass);
if(isset($dbconn)){
mysql_select_db($dbname, $dbconn) or die("<center>Error: " . mysql_error() . "</center>");
}
else{
echo "<center>Error: Could not connect to the database.</center>";
}
?>
I would really appreciate if anyone can teach me how to solve this.. thanks in advance!
As Kerbholz already stated, don't use mysql_* functions, they are really outdated.
Instead use mysqli:
$servername = "eskl.freeoda.com";
$username = "1350048";
$password = "password";
$database = "1350048";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
For your error it got mostly something to do your host doesn't allow remote connections. Try to change the serverhost to localhost or 127.0.0.1
i wrote a php script which should connect me with my database. I also uploaded the files in the public_html section, but it always throws this error :
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /Applications/XAMPP/xamppfiles/htdocs/FoodHelperSwift/db/public_html.php on line 24
Here is the line : $this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
This is my code :
public_html
var $conn = null;
var $result = null;
public $dbhost = null;
public $dbname = null;
public $dbuser = null;
public $dbpass = null;
function __construct($dbhost, $dbuser, $dbpassword, $dbname) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpassword;
$this->dbname = $dbname;
}
public function openConnection()
{
$this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
echo "YESSSS";
echo $this->dbhost;
echo $this->dbuser;
echo $this->dbpass;
echo $this->dbname;
if(mysqli_connect_errno())
{
throw new Exception("Could not connect with database");
$this->conn->set_charset("utf8");
}
}
public function closeConnection()
{
if ($this->conn != null)
{
$this->conn->close();
}
}
}
and
register user
:
require("../db/public_html.php");
$dbhost = "127.0.0.1";
$dbname = "xxxxxxxx";
$dbuser = "xxxxxxxxx";
$dbpassword = "xxxxxxx";
$returnValue = array();
if(empty($_REQUEST["userEmail"]) || empty($_REQUEST["userPassword"])
|| empty($_REQUEST["userFirstName"])
|| empty($_REQUEST["userLastName"]))
{
$returnValue["status"]="400";
$returnValue["message"]="Missing required information";
echo json_encode($returnValue);
return;
}
$userEmail = htmlentities($_REQUEST["userEmail"]);
$userPassword = htmlentities($_REQUEST["userPassword"]);
$userFirstName = htmlentities($_REQUEST["userFirstName"]);
$userLastName = htmlentities($_REQUEST["userLastName"]);
$salt = openssl_random_pseudo_bytes(16);
$secured_password = sha1($userPassword . $salt);
$dao = new MySQLDAO($dbhost, $dbuser, $dbpassword, $dbname);
$dao->openConnection();
The password etc. is right and i also tried localhost, but then i got an error that he cant find the file maybe you could help me.
Most likely you're not following steps provided by your website hosting provider.
Third party hosting solutions usually require you setup your remote IP
From the error message you specified it looks like you're trying to do this from your own home XAMP web service.
First - the basics
:
localhost - won't work from home - because that's going to look for your own MySQL database not the hosted db
Second - logging in from home (or remotely)
read the docs (always a good idea) Remote access to Bluehost MySQL
Use the following configuration settings for connecting to your database
Host name = (use the server IP address)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (the password you entered for that database user)
MySQL Connection Port = 3306
TCP or UDP, either is fine.
Allowing a Remote Server to Access Your Database
Before connecting to MySQL from another computer, the connecting computer must be enabled as an Access Host.
Log into cPanel and click the Remote MySQL icon, under Databases.
Type in the connecting IP address, and click the Add Host button.
Note: You can find and add your IP address directly from this tool. Look for Your IP is: 123.123.12.123 [Add]. Clicking the [Add] link will input your IP into the field box below.
Click Add, and you should now be able to connect remotely to your database.
To troubleshoot this, strip your code down to the basics. Make yourself a little testMyDb.php file, containing only the minimal stuff. For example:
$dbhost = "127.0.0.1";
$dbname = "xxxxxxxx";
$dbuser = "xxxxxxxxx";
$dbpassword = "xxxxxxx";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
Once you have that working, you can proceed to debug your php class and make sure you are setting things up correctly.
Your file named public_html.php contains some code that's part of a php class implementation (for example __construct()), but I don't see a class ClassName { line to set up a class definition. It's possible you've copied some fragments of code from somewhere without getting it all.
If your simple test DOESN'T work, check with bluehost's tech support krewe. You may need some special credentials or database name to connect to MySQL from one of their Windows hosts.
If you're using the MySQL server on a bluehost machine, and trying to connect to it from your local machine, that will not work (especially not with 127.0.0.1). You'll need to configure bluehost to allow remote MySQL connections, and you'll have to use the actual MySQL hostname.
Hi I am making a login/register database. I am not hosting the database on the same server so how do I make it point to my separate domain? Also if you can tell me what the root is pointing to... Thx
Here are my files:
db.php
<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('register');
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
?>
Links (my scripts and original scripts): https://docs.google.com/document/d/1u60X_mKd9z548qrh_VjdyTx3hziiZiYPLUa_rJX11mQ/edit?usp=sharing
For starters, DON'T USE mysql_connect()! Use either mysqli or PDO. Second, don't have your application log in to MySQL as root; create an application-specific unprivileged user (with a password!) for this purpose.
You'll need to create your unprivileged user with connect privilege from the web server's IP or DNS address, and instead of connecting to localhost your PHP will need to connect to the DB server's IP or DNS address, like so:
$dsn = "mysql:host=mysqlserver.mynetwork.com;dbname=register";
try
{
$conn = new PDO($dsn, $appuser, $apppasswd);
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
You could try the following example
$server = "192.168.1.1"; //server name or IP Address
$username = "root"; //database username
$password = "password"; //database password
$database = "mydatabase"; //database to connect to
$connection = mysqli_connect( $server, $username, $password, $database);
if (!$connection){
die("Database Connection Failed" . mysqli_error());
}
else{
//sql statement
}
mysqli_close($connection);
Thanks