Arun vm

Registered
Jul 13, 2019
1
0
0
kochi
cPanel Access Level
Root Administrator
I try to create Db using sql it's showing "Access Denied user"

Here my code .
$servername = "192.168.0.3";
$username = "root";
$password = "[Moderator Note: Removed]";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}


$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}

$conn->close();


echo "string";
 
Last edited by a moderator:

keat63

Well-Known Member
Nov 20, 2014
1,486
124
93
cPanel Access Level
Root Administrator
I don't understand your script as I don't really know PHP.
Did you manually create the user and password (or is that what the script does)
 

sbutler

Member
May 14, 2007
5
2
153
That was the old way with mysqli you have to specify database now.
change $conn = new mysqli($servername, $username, $password);
TO: $conn = new mysqli($servername, $username, $password, $database);
 

sbutler

Member
May 14, 2007
5
2
153
The only way I was able to use that script was to change root MySQL password and try it out on the website outside of WHM/cPanel.
Remotely root didn't work but I did get it to work successfully. While I was able to create the database WHM/cPanel was not aware
the database existed. Not even when the user name was on the prefixed of the database. The final results there is no way outside
of WHM/cPanel to create usable databases. If you are creating a custom installer the user will have too create the database within
cPanel first and then run the installer with the new user, password, and database information. That is how all the Admins are doing
their installs on cPanel. The API'S for WHM will be discountinued in a future release of WHM/cPanel. I Just don't know the date.