-1

Brand new to PHP and I'm going through a few tutorials at the moment. I have created a login.php file that has my hostname, database, username, and password. My test1.php page requires this login.php file and then attempts to connect to it.

I then select a database, attempt a query, and store the results. Here is what I have so far:

<?php   // test1.php
    require_once 'login.php';
    $db_server = mysqli_connect($db_hostname, $db_username, $db_password);

    if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

    mysqli_select_db($db_server, $db_database)
        or die("Unable to select database: " . mysql_error());

    $query = "SELECT * FROM classics";
    $result = mysqli_query($db_server, $query);

    if (!$result) die ("Database access failed: " . mysql_error());

    $rows = mysql_num_rows($result);
?>

The error that I am getting says:

mysql_num_rows() expects parameter 1 to be resource, object given on line 15

Line 15 is:

$rows = mysql_num_rows($result);

What exactly is the resource that I am looking to pass into mysql_num_rows()?

raphnguyen
  • 3,427
  • 17
  • 55
  • 73
  • 2
    You're using `mysqli`, so you should be using `mysqli_num_rows()` – Mark Miller Jun 08 '14 at 01:37
  • 1
    You're mixing `mysql_*` and `mysqli_*` function calls! Change `mysql_num_rows` to `mysqli_num_rows`. – peterm Jun 08 '14 at 01:38
  • Ah, thanks. A lot of the code from the example is deprecated so I have been trying to fix the errors. Guess I forgot one! – raphnguyen Jun 08 '14 at 01:48
  • Please double-check your code for typos before you post it here. Also do not post code directly from your development files. Instead re-create a new example code from scratch with as little code as necessary to demonstrate your issue. Also try to provoke the issue with as little code as necessary. Check the manual for the function in use to catch easy made mistakes. Also use the search. – hakre Jun 08 '14 at 19:40

1 Answers1

1

The mysql_num_rows() expects parameter 1 to be resource occurs when your statement is wrong, it could be that classics table does not exist.

And also use the mysqli instead of mysql

Rod_Algonquin
  • 25,781
  • 6
  • 51
  • 63