I need to access the database. I've downloaded the file where database credential reserved.
The file is mysql.php
$conn = mysql_connect('localhost','user','password') or die("Connection error: " . mysql_error());
mysql_select_db('newadv',$conn) or die("Connection error: " . mysql_error());
IN the server how can I access the localhost and database.
The mysql.php file now is in server and the website is running.
I need to access the database from Mysql interface. How can I achieve this?
I finally got reply from webhosting service. They gave me the credentials to log in.
Thank you every one.
When you want to connect with server.If database present on same server then use host as localhost & database server username & password.If they are on different server then in place of localhost provide the server host details.
like:
$conn = mysql_connect('111.255.255.254','root','root') or die("Connection error: " . mysql_error());
mysql_select_db('newadv',$conn) or die("Connection error: " . mysql_error());
Related
I am getting familiar with WAMP and struggling with very basics. I created a test website and test database, trying to connect db to the site.
Yet I get constantly error instead of connection, error code not telling what's it all about even if site PHP settings are set to "display errors = yes". I have checked creditials dozen of times, they are correct.
Below is the simple code I made, could you please help me out what's wrong with it? Creditials are from sites mySQL manager, changed so that I can't be indentified but in similar shape.
Should the host be something else than a string? Is the PHP script somehow obsoleted/wrong or does this has something do with the fact that I am playing with free and slow web server host?
My code:
<DOCTYPE! html>
<html>
<body>
<h1>Working title</h1>
<?php
$host = "sql123.epizy.com";
$username = "epiz_12345678";
$password = "nottherealpassword";
$dbname = "epiz_12345678_NameofDatabase";
$link = mysqli_connect($host, $username, $password, $dbname);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
</body>
</html>
Thank you for your help!
WAMP is a localhost tool. here you have $host = "sql123.epizy.com"; as database host.
Solution1:
Creating an api [where you can send queries there] in epizy.com webhost to communicate between your server and the database server.
Solution2:
Simply use your own database on WAMP server.
Looking at their support page, it does say:
"Make sure you are connecting from within hosting account.
InfinityFree databases are only accessible from within your InfinityFree hosting acounts. Our database servers are not accessible from other locations, like developer tools on your own computer, websites on other hosting providers, game software, mobile apps and so on. Remote database access is only available with premium hosting."
See here: https://support.infinityfree.net/mysql/common-mysql-errors/
I have an script that i want it to run for more that 5 minutes. But my current hosting service does not allow me to modify the max_time_limit in the php.ini (That is set to 2 minutes)...
So i thought that i could run the script with XAMPP and send the data to my database but i cant connect to the remote database.
This is the code for the connection:
$servername = "217.70.186.108"; //I've also tried with the name of the webpage (metagame.gg)
$username = "the_username"; //the username is not root since I've read that root can only connect from localhost. This user has all privileges. This user was created with the permision to be connected from any server (%)
$password = "the_password";
$dbname = "the_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
It displays this error:
Connection failed: An error occurred during the attempt to connect because the connected party did not properly responded after a period of time, or failed in the established connection because connected host has failed to respond.
Any help would be highly appreciated
I have an issue when I try to access my 1&1 database from the local web app I am coding.
Output: Failed to connect to MySQL: (2002) php_network_getaddresses: getaddrinfo failed: Unknown host.
I use mysqli (which works great with a local database) to connect my app with the DB and I already know the php5 issue with mysqli and 1&1 servers but this would occurs only if my app where on my server.
$mysqli = new mysqli("dbxxxxxxxxx.db.1and1.com", "dboxxxxxxxx", "xxxxxxx", "dbxxxxxxxx", 3306);
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
else
{
$mysqli->set_charset("utf8");
}
Maybe the issue comes from the way I write the host, I tried to add "http://" before but the problem was the same.
Thanks for helping me! :)
Seems a name resolving problem. If you use Linux/MacOS, add the hostname and its IP address in hosts file:
# echo "123.123.123.123 dbxxxxxxxxx.db.1and1.com" >> /etc/hosts
You must replace this example IP for the real one.
at first sorry for my english, i've a important question to resolve.
I'm trying to connect to my dreamhost's database but it's returninng the following error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I've contacted Dreamhost support and they told me that
it looks like the error was the result of using a newly created database
hostname.
I see that the hostname is now working properly
Now, I have a php class to connect to my database.
this is my command to connect:
$data = new MysqlClass('mysql.test.masterweblab.com','user','pass','data_name');
This works on my localhost. Anyone have a solution?
maybe they are using a different version of php or mysql than on your localhost?
try connecting to it like this on a new page and see if this works.
$link = mysql_connect("mysql.test.masterweblab.com", "user", "pass");
mysql_select_db("data_name") or die(mysql_error());
if ($link){
echo "it worked!";
}else{
echo "Failed " . mysql_error() ;
}
mysql_close();
If that doesn't work try pinging the host from a command prompt in windows. Copy the ip address and try.
$link = mysql_connect("THE_IP_YOU_COPIED", "USER", "PASS");
mysql_select_db("data_name")or die(mysql_error());
if ($link){
echo "it worked!"
}else{
echo "Failed " . mysql_error() ;
}
mysql_close();
Let us know what that produces.
if you cant get the ip from pinging the domain there's your problem! Log into cpanel and get your sql servers ip from phpmyadmin.
When I try to run working php code on my localhost instead of the web server, I am getting a connection error.
Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] Connection refused
Any idea how to get the MySQL username, db, and password to work from my local machine? I am using OS X Mountain Lion and Apache.
Do I have to login to the database server and add my IP?
Thanks!
Unless you've changed the default password root is allowed to connect to localhost, so that would be something like this :
<?php
$mysqli = new mysqli("localhost", "root", "", "");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
You can replace localhost by an ip, depends on how your database is configured to allow connections, using localhost or an explicit ip.
in case you have downloaded the code from a server and are trying to make a local replica then you need to update the connection parameters to match your local configuration. You need to update username, password , database etc. as per your local settings.. Hostname you may keep as localhost
Respond back if things are not working and add more detail on how things started like how you set up the code locally..and what things you have tried yet..