0

Im getting errors when attempting to connect a simple script to my webhosting account. (Should i be using "localhost" here or the web host?)

//Setup server connection
$servername = "localhost";
$username = "dummy_dummy"; (CpanelName_DataBaseUserName)
$password = "password";
$dbname = "dummy_exo"; (CpanelName_DataBase)


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

All of the above information is completely correct (User, password, DB name)

Warning: mysql_query(): Access denied for user 'root'@'localhost' (using password: NO) in /home1/name/public_html/index.php on line 38

Warning: mysql_query(): A link to the server could not be established in /home1/name/public_html/index.php on line 38

Im fairly new to php so using a script to connect to an actual hosting account isnt going well for me

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Nihat
  • 65
  • 9
  • 2
    You seem to be connecting with `mysqli`, and then trying to query `mysql_query`. The `mysqli_` library does not work with `mysql_` functions - you should be using the former exclusively. – andrewsi May 13 '15 at 19:19
  • you need to consult their documentation. This isn't the place for questions like these – Funk Forty Niner May 13 '15 at 19:19
  • yeah... where does `mysql_` get into all this? your question/posted **code** does not support the problem. – Funk Forty Niner May 13 '15 at 19:19
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 13 '15 at 19:20

0 Answers0