I have one project running a database on a Cloud9 project. I have created a mobile app which will need to connect to the database by POST to a PHP file which will then run the following code:
$servername = "myusername-projectname-somenumber";
$port = 3306;
$username = "form";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, 3306);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I got the servername by using this in the terminal:
SHOW VARIABLES WHERE Variable_name = 'hostname';
I am getting an error from the other project:
Connection failed: Unknown MySQL server host 'myusername-projectname-somenumber' (0)
***Note: I have replaced myusername-projectname-somenumber and dbname for posting this. I did not forget to fill them out.
Thanks for the help!
Related
So I imported mysql data to phpadmin, under codeigniter and xampp, but when I run the code, I got an error of Class "mysqli" not found
image error
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sex_disaggrated";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
I already change the **.env **file. into this one
database.default.hostname = localhost
database.default.database = sex_disaggrated
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
EDIT:
Php Mysqli
I have bought a database MySQL to use on my domain/host.
I can connect to the database via wampserver (localhost) without problems.
But when I am trying to connect to the host website it gives me an error.
Connection failed: Can't connect to MySQL server on 'mysql-******.net' (111 "Connection refused")
My code:
<?php
$servername = "mysql-*********.net";
$username = "username8954";
$password = "dolphyn1235";
$dbname = "animals";
$dbServerPort = "26313";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $dbServerPort);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Any ideas how to solve this?
Check in your MySQL Server configuration files (my.cnf), find bind-address = 127.0.0.1 then comment them with # at the begining of the line. and then restar your MySQL.
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 want to make connection to my online database, but then I get this error:
Warning: mysqli :: mysqli (): ( HY000 / 2002 ): A connection attempt failed because the " Related party Incorrectly If the answer after a certain time , of the costs Connection failed because " the Confederate host has not responded . C: \ wamp \ www \ array Add in db \ 222.php on line 8
This is my code:
?php
$servername = "db.tapdeleest.nl"; $username = "***"; $password = "***"; $dbname = "***";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "nice";
}
?>
Thanks for helping!
Using new mysqli() you don't add the database name in your connection.
You use mysqli_select_db($conn, $dbname)
<?php
$servername = "db.tapdeleest.nl"; $username = "***"; $password = "***"; $dbname = "***";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "nice";
mysqli_select_db($conn, $dbname);
}
?>
Just advice: Give pdo a try, I feel like pdo is easier.
http://www.w3schools.com/php/php_mysql_connect.asp
I am developing a login/register system for a website but when i'm trying to connect to the database it gives this error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\register.php on line 17
I'm using a external config file wich is been imported.
My config file:
// Connection details
$servername = "127.0.0.1";
$username = "root";
$password = "password";
$dbname = "database";
My connection code:
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
I found one solution that worked to connect but then my config file was useless.
No config but only this:
// Create connection
$conn = mysqli_connect('127.0.0.1', 'root', 'password', 'database');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
If someone nows a solution where i can keep using my config file please post it here.
Thanks in advance.
Well, if the connection works with this values:
$conn = mysqli_connect('127.0.0.1', 'root', 'password', 'database');
But not with this values:
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "cloud";
Why don't you just set the "working" values into your config file. So it would look like this:
$servername = "127.0.0.1";
$username = "root";
$password = "password";
$dbname = "database";
Another solution which is described here includes the creation of a new user, so you don't connect via root, but the new created user.