/    Sign up×
Community /Pin to ProfileBookmark

My first dababase

Hello.

I have an account on a webhosting, where I can run my php codes. There is also database support.

Today I tried to create my first database. Code:

[code]
<?php
$servername = “localhost”;
$username = “nerio”;
$password = “1234”;

// create connection
$conn = new mysqli($servername, $username, $password);

// check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}

// create my first database
$sql = “CREATE DATABASE myFirstDB”;
if ($conn->query($sql) === TRUE) {
echo “Database created successfully”;
} else {
echo “Error creating database: ” . $conn->error;
}

$conn->close();
?>
[/code]

It returned the following error: Connection failed: Access denied for user ‘nerio’@’localhost’ (using password: YES)

What is wrong?

Thank you.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 23.2021 — Make sure localhost is correct -- more often than not it will be on a separate host than your web server, so make sure you're using the correct domain or IP address for the database server per your hosting plan's instructions.

Otherwise, the database user is not defined or not defined correctly, or the password is wrong. Did you create your DB user/password via your hosting plan's control panel or such? (It usually is not just whatever your hosting account login is.)
Copy linkTweet thisAlerts:
@codewitchauthorJul 23.2021 — Hello NogDog. I have just found the login data and a link to phpmyadmin there.

I have seen a video on youtube where the instructor created a database using graphical interface - he was filling numbers into forms and created a database that way. I was thinking if it is possible to create a database just by coding php and SQL (by writing code). Is it?

Thank you.
Copy linkTweet thisAlerts:
@NogDogJul 23.2021 — Yes, it's possible, though frankly not something I typically do. I normally either use whatever admin tool I'm using for that database, or directly entering SQL.
Copy linkTweet thisAlerts:
@yqqweJul 28.2021 — do you type the correct user name and password for the account? and[,](https://it.wenda123.org/)does this account exist? you have to check it first before you make the connection..![](https://it.wenda123.org/static/pix.jpg)
×

Success!

Help @codewitch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...