quick mysql question.
I'm new at php/mysql and followed a tutorial(php/mysql for dummies) so I don't really know what I did wrong or if the tutorial is wrong.
I have a file, "database_connections.inc", that looks like this:
<?php
$user = "username";
$host = "host";
$password = "password";
$database = "database";
?>
With the actual credentials not included for obvious reasons.
Then in another file, login.php, I have:
include("database_connections.inc");
$cxn = mysqli_connect($host,$user,$password,$database)
or die("Query died: Couldnt connect to server.");
I get an error message with the "or die" text, accompanied by a warning:
host xxxxx.000webhost.com is not allowed to connect to this mysql server in....
Why not? I'm sure my credentials are all correct.
I've read in a few places to run some shell statements...but can't really do that, I'm on Windows.
I'm using phpMyAdmin, so hopefully I can do something from there?
Open "database_connections.inc" and change it to look like this:
<?php
$user = "root";
$host = "localhost";
$password = "";
$database = "test";
?>
MySQL is by default configured to work with localhost (or 127.0.0.1), in order to allow "host xxxxx.000webhost.com" as host, open phpMyAdmin and select "SQL" and execute this query;
GRANT ALL ON your_database_name.* TO your_user#your_host_xx.xxx.xx.xx IDENTIFIED BY 'your_password';
Go into PHPMyAdmin, and edit your user.
Under Login Information, there should be an option for "Host"- try adding xxxxx.000webhost.com.
Related
Ok so i am making account system for my website. I am using freewebhostingarea as host. But i dont know what is servername(for connecting to database). Can you help me? Here is my code for connecting:
<?php
$servername = "";
$server = "root";
$password = "my password";
$dbName = "name";
$conn = mysqli_connect($servername, $server, $password, $dbName);
?>
I dont know what is $servername for freewebhoatingarea. Pls reply.
It's all the same actually . I want you to try this 4 steps
After you hit create databaase it will give you an option to name/rename your database so save that name to something like a notepad for your reference
(e.g) freehosting_db_(sampledatabase)
Next to that it that before you hit next on the creation of database kindly remember that password that you are going to make and like the name of the website save it to a notepad so you can remember the password
(e.g) xHsnaAXa123 -> password database
Mostly the server always localhost on SOME freehosting
The servername is automatically generated so look for it. It will be something like
(e.g) freehosting_db_(sampledatabase)_user
And to set that up
$servername = "freehosting_db_(sampledatabase)_user";
$server = "localhost";
$password = "xHsnaAXa123";
$dbName = "freehosting_db_(sampledatabase)";
PS: This is mostly how you setup a connection from your database to your server . But it is always depends on the the hosting that you are going to use . Godadday, Hostgator, 000webhostingapp, they are all alike on how setting it up .
my localhost is saying error like Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\registration\includes\db.php on line 3 on the browser I have all things done here's the image of the error in browser.
1: here is the image which is facing the error
and also if I am doing something wrong in my code editor then here's the image of the db.php db.php files code
This issue is tricky. But, how i went around it was straightforward.
in your mysqli_connect(_,_,_,_) arrange them in this order of "localhost", "user", "password", "database_name";
You may have an invalid password.
Edit: To me it looks like you're failing to actually pass parameters to the connection function, are you including / importing the variables?
You have passed invalid credentials (user name and/or password) when trying to connect to the database. What to pass can't be answered here because only you (the database administrator) would know about the existing user accounts.
To add an user account to a MySQL database see MySQL :: MySQL 5.7 Reference Manual :: 6.3.2 Adding User Accounts[^]. This requires connecting as root and providing the root password if one has been set.
The second is a result of the first and of using the wrong error function. For mysqli_connect(), you have to call PHP: mysqli::$connect_error - Manual[^] instead of mysqli_error() upon errors:
Hide Copy Code
$connection = mysqli_connect ($host, $user, $password) or die('Not connected : Ah sh*t ' . mysqli_connect_error());
change back your password to null
go to mysqladmin root (C:\xampp\mysql\bin) and type
mysqladmin --user=root --password=oldpassword password""
dont type any character when request new password, just push enter and enter
viola refresh your phpmyadmin page,
the problem caused by changing password via command window, just change the password via phpmyadmin page to avoid such error, http://localhost/phpmyadmin
This is how you should connect your database using mysqli :
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$db = new mysqli($servername, $username, $password, $dbname);
?>
I have had the same problem trying to install OpenCart on xampp (32bit). I was completing the information that I thought was being requested when in fact all I was being asked for was the name of the database. Leave all fields as oriinal just the name of your DB.
Leave password blank.
make sure this mapping is done
IN path\xampp\phpMyAdmin\congig,inc
/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = YOUR_DEFAULT_PASSWORD;
and you connection file
<?php
$servername = "localhost";
$username = "root";
$password = YOUR_DEFAULT_PASSWORD;
$db = "ecommerece";
$con = mysqli_connect($servername, $username, $password,$db);
your DB_HOST is your mysql server ip (most time is localhost)
your DB_USER is your User of Mysql (most time is root)
your DB_PASS is your Password of Mysql User (most time is none)
your DB_NAME is your name of your database in Mysql server
I'm running into an issue while trying to link a MySQL database to a PHP file.
Im trying to setup this PHP login system from Github and currently I'm trying to setup the dbconf.php file. This is the code where I'm trying to link the database to.
<?php
//DATABASE CONNECTION VARIABLES
$host = "localhost"; // Host name
$username = "user"; // Mysql username
$password = "password"; // Mysql password
$db_name = "22445671_login"; // Database name
//DO NOT CHANGE BELOW THIS LINE UNLESS YOU CHANGE THE NAMES OF
THE MEMBERS AND LOGINATTEMPTS TABLES
$tbl_prefix = ""; //***PLANNED FEATURE, LEAVE VALUE BLANK FOR NOW***
Prefix for all database tables
$tbl_members = $tbl_prefix."members";
$tbl_attempts = $tbl_prefix."loginAttempts";
The MySQL Database is named 22445671_login
I am just looking for a way to link the MySQL database to my document
Any help is greatly appreciated, thanks.
As put into my original question before it was removed. My website is hosted at at-space which comes with a PHPmyAdmin account linked to my website, I dont know how to link the MySQL database since I don't know if the username and password are just username and password. And I dont know if the host would be 1. My Website 2. atspace or 3. PHPMyAdmin
Where is your database hosted?
You might need to replace "localhost" with the hostname of your server:
$host = "localhost"; // Host name
Make sure you have the correct username and password
Make sure the user has the necessary permissions
Not sure if PMA has this feature, but SIDU has this feature:
<?php
$url = 'http://example.com/sidu54/conn.php'
.'?conn[host]='. $host
.'&conn[user]='. $username
.'&conn[pass]='. $password
// OR .'&conn[pass]='. $encryped_pass .'&conn[penc]=1'
.'&conn[dbs]='. $db_name
.'&conn[eng]=PDO_mysql'
.'&conn[char]=utf8'
.'&cmd=Connect'
.'&url=db.php'
.'&id=1,'. $db_name;
echo 'Click here to manage database';
I have read up on the above error and from the way I understand, there could be many reasons that error pops up. I will try to be as specific as possible.
I have made a php file to do a simple database connect:
<?php
header('Access-Control-Allow-Origin: *');
$servername = "188.166.***.***";
$username = "root";
$password = "mypassword";
$dbname = "vod";
$con = new mysqli($servername,$username,$password,$dbname);
if($con->connect_error){
die("error ".$con->connect_error);
}
echo "success";
?>
When I run the above code I get the error:
Can't connect to MySQL server on 'XXX.XXX.XXX.XXXX' (111)
When I enter XXX.XXX.XXX.XXX in the URL bar I am taken to the index.html file of the server. And when I enter XXX.XXX.XXX.XXX/phpmyadmin I am taken to phpmyadmin.
I hope I made my question clear.
It depends on you if you want to do it like this:
CREATE USER 'user'#'%' IDENTIFIED BY 'userpassword';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'%' WITH GRANT OPTION;
you can run it at your query database. just change user and password. good luck
I am having some problems with my database. I created a user, and a database, but I can't seem to access it with php.
My code is:
$host = 'anapaiva.pt:2082';
$user = 'anapaiva_p1';
$pass = 'xxxx';
$db = 'anapaiva_mcmm1';
#mysql_connect($host, $user, $pass) or die('err: '.mysql_error());
#mysql_select_db($db) or die('err: '.mysql_error());
And on the webpage, appears the following errors:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'anapaiva_p1'#'apollo' (using password: YES) in /home/anapaiva/public_html/mcmm/connection/dbconn.php on line 6
Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/anapaiva/public_html/mcmm/connection/dbconn.php on line 7
The same code was working with my other server, hungergamesportugal.com, but I can't seem to upload the sql file to that database (it says I don't have permissions... I don't know why), and on this server it allows me to import the sql file, but I can't seem to access the database.
Can someone please help? :/
You're using the wrong port. 2082 is for cPanel. 3306 is for MySQL (usually).
Generally, you can omit the port entirely:
$host = 'anapaiva.pt';
You also need to assign the connect function to a variable:
$dh = mysql_connect($host, $user, $pass);
So that you can close the connection when you're done with it:
mysql_close($dh);
You can allow permission using cpanel, add permission to remote mysql. I don't remember exact name, but it was something like, remote database. on clicking you can add ip address to allow database permission. This may help you. search remote database at cpanel. May be this help you, http://forums.cpanel.net/f354/enable-remote-access-customer-database-251951.html
Test same user on localhost
$mysql_host = "localhost";
$mysql_database = "db_name";
$mysql_user = "root";
$mysql_password = "password";
$con = mysql_connect($mysql_host,$mysql_user, $mysql_password);
mysql_select_db($mysql_database, $con);
OR
Check user privileges
Using GRANT statement check whether user has rights.
Reference: http://dev.mysql.com/doc/refman/5.0/en/show-grants.html