Hi,
I’m a newbie to databases. What I’ve done is:
<?php $con = mysqli_connect(‘localhost’, ‘admin’, ‘password’, ‘test’) or die("Connection failed: " . mysqli_connect_errno()); ?>
Somehow, now matter what I try, it keeps giving me a connection error. Am I doing something wrong?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $100 of credit to try our products over 60 days!
MySQL users are identified by a username and host. Additionally you should only be using your MySQL admin account to administer the MySQL server itself but not to access various databases and not to read and write information that are connected to by apps. This is for security.
Since you have created a database already called test you will want to create a new user that will access that database and read/write data to it.
To do that login to mysql as your admin account and create a user with access:
Here you are creating a new user called
testuser
which can connect fromlocalhost
with the password you specified.Then you are granting that user privileges to access, read, write, etc to the database
test.*
. When you writetest.*
that means you are giving this user access to the database test, and the*
means all tables for that database.You can also find more in depth information about users and permissions here: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql