0

This is my dbconnect.php and I believe it's fine

When I try to connect it and go to my site to login it says that access is denied for me when it's listed as all rights. The site I use said it just means my code failed to connect to the database. So did I do something wrong?

<?php
error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );
if(!mysql_connect("mysql12.000webhost.com","******","******"))
{
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db("dbtest"))
{
die('oops database selection problem ! --> '.mysql_error());
}

?>
Jayy
  • 49
  • 8
  • 1
    Welcome to Stack Overflow! [**Please, don't use `mysql_*` functions in new code**](http://stackoverflow.com/q/12859942). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). – Rizier123 Jan 09 '16 at 05:46
  • Oh I see, I had heard of the new mysql but I never figured I'd have to change my style. Do you have an example of something I can change it to? Would be greatly appreciated – Jayy Jan 09 '16 at 05:51

1 Answers1

1

Use mysqli or PDO, mysql is going to deprecated.

Try This:

<?php $conn=mysql_connect('localhost','root','')or die(mysql_error());
mysql_select_db('db')or die(mysql_error()); ?>
Divakarcool
  • 473
  • 6
  • 20