我正在尝试通过 php 连接到数据库。我做了很多时间。但我想知道我的表中有多少行。我试过使用php手册,但是我很困惑。
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
上面的代码适用于:
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
但是当我决定使用
$link = mysql_connect("localhost", "mysql_user", "mysql_password","database");
它发生了这样的错误:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ...
代码之间有什么区别?我该如何解决?提前致谢