0

I 'm trying to connect to mysql local server ,but mysql_select_db function return false when I select first_try_books database .

      <?php
 $conn=mysql_connect();
 if($conn) print("Connect Successfully");
 else {echo "error in connection ... try again "; die();}
if( mysql_select_db("first_try_books",$conn))
    print("select Successfully");
else
    print("error select");  
if( $tab=mysql_query("SELECT book_id FROM lib",$conn))
    print("query Successfully");

      ?><!-- end PHP script -->

this is the database

sepeee
  • 47
  • 1
  • 6
  • try to see what the error is. `mysql_select_db("first_try_books",$conn) or die(mysql_error())` – roullie Dec 02 '15 at 00:23
  • [don't use `mysql_`](http://stackoverflow.com/a/12860046/1028804) – Memor-X Dec 02 '15 at 00:25
  • First get your `mysql_connect()` correctly coded RTM http://php.net/manual/en/function.mysql-connect.php it has parameters that are rather important. Also Please dont use the `mysql_` database extensions, it is deprecated (gone for ever in PHP7) Especially if you are just learning PHP, spend your energies learning the `PDO` or `mysqli_` database extensions, [and here is some help to decide which to use](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – RiggsFolly Dec 02 '15 at 00:26
  • @roullie the error is Access denied for user ''@'local host' to database 'first_try_books' – sepeee Dec 02 '15 at 00:27
  • See my previous comment – RiggsFolly Dec 02 '15 at 00:28
  • @RiggsFolly Ok,I'll do that .thanks :) – sepeee Dec 02 '15 at 00:30

1 Answers1

0

How about using a different driver to connect to your BD?

you can use PDO

$SQL= new PDO('mysql:host=localhost;dbname=data_base','user','pass');

or mysqli

$SQL= new mysqli('localhost','user','pass','data_base');
PekosoG
  • 246
  • 3
  • 9