Can't connect to Dreamhost's database - php

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.

Related

Trouble with basic database connection with PHP

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/

How to connect to a remote computer running a sql database via php

I am running an apache webserver on a server on my local network.
I have a microsoft SQL server 2008 r2 database running on a different machine on the same network. My webserver is hosting a lot of pages, and are all fine and can be accessed locally and externally. However, when I try to connect to the SQL database using php, I get hit with the following error.:
Failed to connect to MySQL: No connection could be made because the target machine actively refused it.
I am at a total loss at this point as I have opened port 1433 and have spent hours trying to figure this out.
The code that I am using is a very basic connect script:
<?php
// Create connection
$con = mysqli_connect("mycomputer", "myname", "password", "my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
If anyone can help, I would sincerely appreciate it as iIam about to give up on this project!!!
Thank you in advance.
As i understand - you use MS SQL , so you must use mssql_connect not as mysqli_connect
Check here
Cause its another database and another driver (extension ) using to connect

Cannot connect to MySQL database, socket error

I'm new to php, and while trying to make a connection on one of my pages to the database I set up on the phpMyAdmin page of my site.
I get this error:
"Database connection failed: Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (46) (2002)"
I don't know what a socket is, or why it's trying to go to what looks like a temp file, so I don't even know where to being to troubleshoot this.
The code I'm using to make the initial connection is this:
<?php
define("DB_SERVER", "localhost");
define("DB_USER", "xxxx");
define("DB_PASS", "xxxx");
define("DB_NAME", "tester");
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
// Test if connection occurred.
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
I know I should have access to the MySQL databases, since I logged on and made them myself.
I previously set the page up by using WAMP on my computer, and everything worked fine.
It's just when I tried making it live on the site that I ran into this error.
Any help would be awesome!!
Try using 127.0.0.1 instead of localhost.
If that does not solve it, and you have root access to your server, try the following command
service mysql restart
To restart the mysql server.
The first option will probably work. Again, if you have root access to your server, you should change the mysql config to support sockets, since it's better than the TCP-ip connection.
After contacting my hosting service several times, it seems the error occurred because my hosting service recently changed their specifications and now uses "mysql" instead of "localhost" in the host and server fields. I had used "localhost" before with another host service, so I didn't think to change this, and the latest help articles on my host's website had not updated to reflect this.

Connecting to MySQL Database with Code Hosted Locally

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..

Connecting to MySQL from another IP/Website

I've newly set up a VPS and installed WHM.
I have a MySQL DB on this server which I am able to connect with using a desktop SQL application called Sequel Pro.
Using PHP I have set up a subdomain which I want to connect to this DB, I have used the same details as the Desktop Client but I keep receiving PHP Warning: mysqli::mysqli(): (HY000/2003) messages in my PHP error_log.
I'm completely stumped as I thought I would be able to connect to the DB from another website. I have add % to the cPanel Remote MySQL® and still no luck.
Could someone please point me in the right direction.
<?php
$mysqli = mysqli_connect("HOST_IP","DB_USER","DB_PASS","DB_NAME");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$q = $mysqli->query("SELECT COUNT(*) FROM users");
print_r($q);

Categories