Mysql/PHP Access Denied

Swaggots

Member
Sep 22, 2013
98
18
So i'm working on this thing. I got this php code :

Code:
<html>

<head>

</head>

<body>

<?php
    $con = mysql_connect("xxxhostxxx","xxxuserxxxx","xxxpassxxx");
    if (!$con) {
        die("Cannot connect: " . mysql_error());
    }

    if(mysql_query("CREATE DATABASE snippets", $con)) {
        echo "Database created";
    }
    else
        echo "Error: " . mysql_error();

    mysql_close($con);
?>


</body>

</html>

but when i'm checking the page out online, it gives me the following error:

Error: Access denied for user 'xxxxx'@'10.1.1.27' to database 'snippets'

Thanks for the help guys
 

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
Make sure you set the MySQL IP address to a wildcard connection (if it's hosted on web hosting) or try and use local host if it is on your local host
 

Balls

Member
Jun 1, 2013
251
46
If you are trying to create a database through php:
PHP:
<?php

try{
    $con = new PDO('mysql:host=localhost','root','password');
   
    $con->exec("CREATE DATABASE snippets;");
               
}catch (PDOException $e) {
    die("Error: ". $e->getMessage());
}
?>
 

Users who are viewing this thread

Top