Unable to connect Website to my phpmyadmin MySQL database - php

Before I get into the question, I ran into a lot of questions, both on this website, as well as a bunch of others, however none of the solutions there helped, and so decided to post a question with my exact situation.
So I am currently building a website, and am trying to connect it to a MySQL database I have created on phpmyadmin through hostgator. I am currently using 000webhost.com to host my webpages, as the computer I am working on does not have an ftp client, and am unable to install it as of now. As such, I decided to upload the files onto there temporarily as I build it, as they are dynamic webpages. Whenever I load up the page, however, I receive this error:
Warning: mysqli_connect(): (HY000/1045): ProxySQL Error: Access denied for user...
where the "..." just lists my username and filepath to the file.
this is my php code to connect to the database:
<?php
define("DB_SERVER","localhost");
define("DB_USERNAME","**user**");
define("DB_PASSWORD","**password**");
define("DB_DATABASE","**database_name**");
if(!mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD)){
echo"Failure";
}
else{
echo"Success!";
}
?>
I double- and triple-checked the database username, password and name, however to no avail. Thanks a lot in advanced!

You have to change your DB Server location due to you are not using the same web server as your hosting.
Change this
define("DB_SERVER","localhost"); to define("DB_SERVER","YOUR_REMOTE_DB_SERVER");
Also you have to enable remote access in your mysql database.
You can check this similar topic

To answer your initial question, there is no call to connect.
define("DB_SERVER","localhost");
define("DB_USERNAME","**user**");
define("DB_PASSWORD","**password**");
define("DB_DATABASE","**database_name**");
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
then test your connection.
As for setting up a localhost for development, if you are using Windows I would suggest XAMPP, it is pretty much download and say yes to all.

Related

WampServer, mysqli_connect (HY000/1045) Access denied for user

I'm using wampserver 3.2.0 and mysql 8.0.18.
I already reinstalled the wampserver and started everything from the begining after many tries, so now with fresh reinstall and clear datas this is what i did:
Set password for the root "pass123", after this i created a database (testdb) at wampserver>mysql>mysql console (i was logged in as root), then filled it up with the data i needed. Checked the user accounts/privileges, and the database privileges, i have all the privileges everywhere as root, but still i get this error message: screenshot about the problem
my code:
<?php
$ser="localhost";
$user="root";
$pass="pass123";
$db="testdb";
$connect = mysqli_connect($ser ,$user ,$pass ,$db) or die("Connection Failed");
echo "Connected!"
?>
Thanks in advance! (i'm new to php)
I solved the problem by specifying the exact port number used by mySQL.
The standard port is 3308, so just change the following line:
$ser="localhost:3308";
Not the actual SOLUTION, but, it works fine. Easy.
If you have the same problem, DO NOT use WAMP, use XAMPP instead.
With the same settings, it works.

Dreamweaver CC can't connect to my local XAMPP testing server via PHP

I'm a newbie at PHP, and coding in general, however I'm attempting to set up a simple user login/registration page using a MySQL database via phpmyadmin. After hours of trawling through forums etc, I could only find outdated information with no relevance to my specific issue.
My set up is as follows:
XAMPP v3.2.2, phpMyAdmin (Apache/2.4.18 (Win32) Open SSL/1.0.2e, PHP/7.0.3 with mysqli PHP extension/ Maria DB Server Type) & Dreamweaver CC.
I have set up a new site & a new server (following various online tutorials that show the same method) but when I attempt to define a connection via recordset, it displays the error message:
"Your PHP server doesn't have the MySQL module loaded or you can't use the mysql_(p)connect functions."
I have the MySQL module loaded and it's working fine as I am able to connect to phpmyadmin. Apache module is loaded and it's working fine as I am able to connect to my localhost in the web browser. Details for testing server have been set up in C:\xampp\htdocs\mysite and changed to PHP/MySQL server model.
The database and tables have been created in phpmyadmin and ready to go, however I just can't connect to them through Dreamweaver CC.
I've tried changing information in config.inc.php, tried changing extension_dir path to mysqli.dll in php.ini (which is in C:\xampp\php\ext) and also uninstalled and reinstalled XAMPP twice.
I believe that my phpmyadmin and XAMPP server are working fine, however I just can't seem to have any success linking it to my php pages in Dreamweaver CC.
Am I missing anything obvious?
Any help/clarity would be greatly appreciated as I'm currently losing all hope! Thank you!
i know this is a little old but i was able to fix the problem.
xampp by default only has MySQLi dll activated. go to the php ini file and uncomment the MySQL dll and restart the Apache server.
this worked for me. also cs6 need the database extension installed.
The error says "Your PHP server doesn't have the MySQL module loaded or you can't use the mysql_(p)connect functions."
In php7 mysql_* has been deleted you have to use mysqli or PDO instead.
You can read more about hereenter link description here
The error shows that you are using mysql_* extension. Your code must look like these: mysql_connect("localhost", "user", "password");. You have to change this to $conn = new mysqli("localhost", "user", "password", "database");. Check this link to review how to change your

How to use SQLyogTunnel_ciom.php

I am working with mysql credentials where I always get an error : access denied for root#user
I have ssh details so I used heidisql and sqlyog to connect to database, It worked.
Now I have to write code for this database using php.
mysqli_connect gives the same error.
I searched and tried many things (like using ssh -fNg -L) but non of them worked for me then some how I got a file 'SQLyogTunnel_ciom.php'
but I have no idea how to use it. I tried to include it and call its function but that is not working either.
Kindly suggest me how to work around in this situation.
http://blog.webyog.com/2012/10/31/think-beyond-phpmyadmin-to-access-mysql-on-a-shared-host/
This blog post explains how you can create something like SQLyogTunnel.php to access database in a shared hosting.

MySQL No Route to Host, mysqli_connect(): (HY000/2002)

I am trying to install BugZilla on Mac OS X 10.9 (Mavericks).
I'm hitting a snag with my MySQL configuration.
I have installed MySQL from the DMG Image mysql-5.6.14-osx10.7-x86_64
MySQL seems to be installed and running ok.
I have created a user called bugs, and a database called bugs.
I confirm that I can login to MySql from the terminal command line, using the bugs username and password, and access the bugs database.
However the installation of BugZilla fails with an error connecting to MySQL. I tried a simple test and wrote this php file:
<?php
// Create connection
$con=mysqli_connect(“localhost”,”bugs”,”********”,”bugs”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
But it fails at line 3 with:
Warning: mysqli_connect(): (HY000/2002): No route to host in /Users/bugzilla/Sites/test_my.php on line 11
Failed to connect to MySQL: No route to host
Why is it that I can connect from the command line, but not from php?
We experienced this error because the ip subnet used by our vagrant environment was the same as the subnet of the database server. We needed to recreate the database server on a different subnet.
I just experienced a similar problem but through which it looks like there was a different problem case. I was getting the same error:
Failed to connect to the database, please check your credentials: No route to host
And we were able to figure out the problem was actually that the disk space of our database was full (our server administrator was out sick for a while, and we automatically make snapshots, but only manually delete them on a regular basis. After a few days, the snapshots took up the space of the entire server and rendered it unresponsive).
I don't know if this will be the answer to anyone with this issue, but if someone does stumble upon this same error, hopefully this might help.

Confusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)

So the problem changed from what it was, i'll leave the original question below to prevent bad reviews on answers like I had after someone editing his question I answered :
So I am working on a (really lame) shared hosting which has PDO installed, but it doesn't work.
With default parameters
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
it throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
With a simple mysql_connect, it works.
And the socket path seems correct (both phpinfo and this query :
show variables like 'socket';
confirm.
Localhost redirects to 10.103.0.14 (this data comes from mysql_get_host_info() and in phpMyAdmin)
In the PDO, if i replace localhost by 127.0.0.1 i will get
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
And if i replace localhost by 10.103.0.14 :
Access denied for user 'USER_NAME'#'10.103.0.14' (using password: YES
Both IP adress (127.0.0.1 and 10.103.0.14) work with mysql_connect.
So apparently the problem comes from the PDO connection.
Does somebody knows where this could come from, or/and any way to fix it ?
Some server datas :
The PHP Version : 5.2.10
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
No command line possible.
(i know it should be the tech suport's job, but they're reaaaaaly slow)
Thanks
Previous question :
How to find the mysql.sock on a shared host (tricky way needed...)
So today's problem is : The PDO connection doesn't work on a shared host, and it's supposed to (it's installed on the server).
Just a basic PDO connection :
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
A regular mysql connection :
mysql_connect("localhost", "THE_USER", "THE_PWD") or die(mysql_error());
mysql_select_db("24DLJLRR1") or die(mysql_error());;
echo 'Connected to database <br/>';
works fine.
So apparently it cannot find the .sock.
I think specifying the correct address should work, i tried some "classic" mysql path that I found on internet, without success.
The phpinfo says it is at this adress (/var/lib/mysql/mysql.sock)
(The PHP Version is 5.2.10)
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
So i am trying to figure out where the hell it is !!!
I tried to look in the phpMyAdmin interface, but i couldn't find the info, plus it seems that phpMyAdmin connects to a different server (it has a different IP adress, and trying to connect to it with php gives a "Wrong password" error). The mysql_connect also connects to this adress, i think it redirects to a different server with some internal password/login.
Well if you have any idea of how to obtain this info (the provider's technical support is "fixing the problem"... it's been 1 month...).
Also maybe the problem comes from somewhere else, but the same stuff works on other shared hosts...
The need of PDO is because I use the Symfony framework with Doctrine for this website, and the Doctrine plugin needs PDO... I don't want to redo the website from scratch !
Thanks for your help !
This was already marked as answered, but not really solved (without changing databases).
So, just in case someone like me also experiences this problem...
The easiest way to fix this is to first get the socket path (either by looking in the php.ini file or by using: phpmyadmin or the console (or construct it in mysql or mysqli)
...to run the following query (anything but PDO):
show variables like 'socket'; //as mentioned by symcbean
THEN, in the PDO connection string, change it to use the socket instead of a hostname:
$dbc = new
PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=$DBName",
$User, $Password, array(PDO::ATTR_PERSISTENT => true)); // using
persistent connections
This worked for me.
FWIW, I had this issue and changed my host from 'localhost' to '127.0.0.1'.
I have no clue why localhost wasn't working, but that did the trick.
Odd thing is, we have tons of servers and it works on almost every one using 'localhost'
Is your server running with SeLinux enabled (enforcing)? If it is, try running as root:
# setsebool -P httpd_can_network_connect on
Can you try 127.0.0.1 as the server name instead of localhost?
IIRC, with some mySQL drivers / adapters, this decides whether the socket is used for establishing the connection or not.
Using the connection which works, run the query:
show variables like 'socket';
(this behaves just like a select statement)...and you'll get the path of the running socket.
Then check the file permissions.
I had the problem that production version worked just fine and a test version wasn't able to connect PDO :/
both versions was located at same servers, test in a sub directory.
The fix was replacing in DSN the localhost for ip.
'mysql:host=localhost;dbname=db'
became
'mysql:host=127.0.0.1;dbname=db'
try:
exec('`which mysql_config` --socket');
this should show you the configured socket.
I found the reason for the strange behaviour. If bind-address is different to 127.0.0.1 or 0.0.0.0 (all addresses) PDO can't connect to 127.0.0.1.
For what it's worth, I found this page after having the exact same issue. I am on a server running Apache & PHP only - MySQL is installed on another machine. I tried both the DNS name of the server and its IP and confirmed I could ping it. A PHP app on the same machine is talking to the database fine, using old syntax mysql_connect( ). But PDO from the CLI was throwing this error.
The solution for me was to check my DSN. Any typo in the DSN itself is ignored silently, and PDO assumes you mean localhost. My issue was I had "name=" instead of "dbname=" in the DSN.
The Issue In the Mysql configuration It you need to disable the option of skip-networking
in my.conf configuration file this should work fine
reference
http://www.wolfcms.org/forum/post7098.html#p7098
I just solved a similar issue. My guess is you probably replaced your mysql_connect() statement with the PDO equivalent. Don't forget you still have lots of other code dependent on that old connection statement. Try keeping the mysql_connect in place while writing in the PDO code.
What worked for me was specifying the port number like so:
mysql:hostname;port=3306;dbname=dbname;
This got it to work when connecting to a local database. Now I'm working on getting it to work with a remote db.
My problem may be different to the OP, but I thought it was worth posting. I did a software upgrade on a VM, then rebooted and got the OP's error message. It turned out to be an out-of-memory problem preventing mysql from starting. Deleting a few large files made the problem go away.
One year later, I found a solution for this issue : using a SQLite database. PDO worked fine, but not with MySQL
** EDIT ** as everyone is downvoting this: This solved my issue (I'm the OP). I was using Doctrine, so switching RDBMS was easy and quick. Also the website was some a home made CMS, with very few trafic, so SQLite was fine.
I know it's not a real "Answer" to the problem, but if someone is in the same context: a crappy shared hosting which you can't change with this weird PDO-MySQL bug AND is using doctrine. This IS a solution. I can delete this answer, but if I had thought of this at the time of the OP, I would have saved a lot of time.

Categories