I am trying to connect to database through php.I did it lots of time. But I want to know how many rows exist in my table. I've tried to use php manual, however, I was confused.
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
The above code worked on :
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
But when I decided to use
$link = mysql_connect("localhost", "mysql_user", "mysql_password","database");
It occurred an error like this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ...
What is difference between codes? And how can I solve it? Thanks in advance