Php with mysql won't connect - php

I've tried every way to connect MySQL with PHP and it doesn't work. I think there may be a issue with phpMyAdmin and MySQL terminal because when I make a table in the terminal it doesn't show up in phpMyAdmin. Is that unusual?
Also when I click on Server: localhost in phpMyAdmin a 404 error message comes up, Is that normal?
I used this code which puts a 0 in my browser which means it should be working. If I change my credentials it will echo 1045. So it should be working.
$db = new mysqli('localhost', 'root', 'root', 'db_demo');
echo $db->connect_errno;

404 means your request not found in the server. Make sure whether your phpmyadmin located in the right directory.
If everything is OK you should configure phpmyadmin, please find file named "config.inc.php" to setup your host, mysql username, mysql password, etc.

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.

Unable to connect Website to my phpmyadmin MySQL database

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.

Error connecting to SQL host, PHP Script: PHPVALLEY Microjob Script

I installed the php script and all wen well but the problem is at the final step, when I need to fill the database information, when I field the database information I find that i am getting an error that says "Error connecting to SQL host", so I try and try in different ways but there is no solution, nevertheless, I installed the same script on my localhost and all went well without problems, my Hosting Provider is: Siteground
Filling Database Information Image
Showing the Error Image
You must grant write permissions to the connect.php file for the user who is running the web service for example apache.
Have you ssh access to the server?
If your application cannot connect to the database you should make sure that:
Your application is using the correct MySQL hostname: localhost
Your application is using the correct MySQL database / username /
password.
Don't forget to specify your MySQL username and database with the
prefix yourusername_ in front of its given name. For example, your
cPanel username is siteground and you have named your database
joomla. In this case you have to refer to your database as
siteground_joomla;
Source: https://www.siteground.com/kb/my_script_cannot_connect_to_my_database_/
Another good idea would be to try to use your cPanel username and password for the Database User and Database Password. This will rule out whether you have granted all privileges to your database user.
Also you should change the permissions of your connect.php file to 755, as if you set them to 777, this will cause an internal server error.

MAMP cannot connect to localhost

Big picture: trying to update a 5 year old WordPress site without losing all the calendar plug-in posts.
Macro: downloaded MAMP to setup a local test site. Cannot get past index page to connect to database.
What works:
Index page shows my test sites (I have three versions of wordpress
Installed (3.0.5 / 3.9.1.1 / 4.4.2), so I can incrementally test and
upgrade)
I can login to phpMyAdmin no problem
I exported the old database to a .sql file, then imported it up to the new Local database, it showed up fine, but tells me "Your PHP MySQL library version 5.1.73 differs from your MySQL server version 5.5.48"
The wp-config.php usernames and passwords all match to the database
After many searches and most of the day trying different things, I am stumped. Obviously, I am a complete noob to MySQL and PHP.
What I have tried:
Changing port to 90 instead of 80
Changing the user to 'root' and 'admin'
Changing from define('DB_HOST', 'localhost’); to define('DB_HOST', '86.42.246.7:80’); and define('DB_HOST', '86.42.246.7:90’);
Notes:
I initially edited the files with textedit, but noticed it was changing single quotes to leave syntax errors - now I'm using Dreamweaver.
Is it possible I could just import each table one at a time into a newly created database?
Please help me out!
EDIT
I changed the database password, but I got this error message
"phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server."

Where is /usr/local/lib on online server

I have a server hosted on 000webhost.com
In the file manager there is a public_html folder where I store my website files, but no \usr folder.
Generally I could just access this file through the command line or terminal but this is not the case on this server. Unless there are command line tools that I simply couldnt find (I know it is a linux server);
I ran phpinfo() and the configuration file path was in usr/local/lib but I have no idea how to access that.
Any ideas? Thanks in advance.
Go to http://www.000webhost.com/faq.php look at the section on connecting to MySql. Your solution is likely there.
Here is a synopsis:
If you cannot connect to MySQL server, there could be some causes:
- Incorrect MySQL hostname.
Never use 'localhost' as your MySQL hostname! You can find your MySQL hostname by logging on to members area, entering control panel and clicking on MySQL icon.
- Incorrect MySQL username / password or database name.
You can find / setup MySQL username and database by clicking on MySQL icon from control panel. And you can change MySQL password by clicking on phpMyAdmin icon.
- Database failed to setup.
In a very rare cases MySQL database can fail to setup. To confirm this, please try to enter phpMyAdmin for any database. If you see database there, that means it setup was successful. And if you get access denied error by trying to enter phpMyAdmin, please delete the database and setup the same MySQL database again.
Please note that always you must give about 1 minute for any changes to apply on server.
If you still unable to connect to MySQL you check if it is server or your script problem in this way: if you can enter phpMyAdmin and see you database there, that means everything is working fine on our side. It's a problem with your PHP script.

Categories