Hi I have been struggling with this query for a while now

I need to get the number of rows inserted into my database table, but I keep getting this error I can't seem to get rid of.

$result3=mysql_query("INSERT INTO dest_table.create_info SELECT * from 
Profusion.source_cdr");
$num_rows = array($result3);
$progress=mysql_num_rows($num_rows);
echo $progress;

The error I get is

mysql_num_rows() expects parameter 1 to be resource, array given

It will be highly appreciated if I get this resolved

Dani AI

Generated

The error happened for two reasons: the INSERT query never returns a result resource (so mysql_num_rows() is the wrong function for that kind of query) and the code wrapped the query result in an array before calling mysql_num_rows(), producing the specific "array given" complaint. For an INSERT ... SELECT you want the number of rows affected by the INSERT, not the number of rows in a SELECT result resource.

As suggested, use the "affected rows" API and move away from the old mysql extension. Example patterns:

// mysqli (procedural)
$link = mysqli_connect('host','user','pass','db');
$sql = "INSERT INTO dest_table (col1,col2) SELECT col1,col2 FROM source_db.source_table";
if (mysqli_query($link, $sql)) {
    echo mysqli_affected_rows($link);
} else {
    echo mysqli_error($link);
}
// PDO
$pdo = new PDO('mysql:host=host;dbname=db','user','pass');
$stmt = $pdo->prepare($sql);
if ($stmt->execute()) {
    echo $stmt->rowCount();
} else {
    // handle error / exception
}

Quick troubleshooting checklist:

  • Don’t wrap the query result in an array; inspect it with var_dump() to confirm its type.
  • Call the affected-rows function immediately after the INSERT on the same connection.
  • Check and display connection/query errors (mysqli_error / PDO exceptions) when false is returned.
  • For large bulk inserts, wrap the operation in a transaction to improve performance and ensure you get a reliable affected-rows count.

This addresses the original problem reported by and expands on ’s correct advice to use affected-rows and to migrate to MySQLi or PDO for modern PHP.

Recommended Answers

All 2 Replies

Use mysql_affected_rows() instead of mysql_num_rows($num_rows). Also use MySQLi or PDO libraries, since the MySQL library is going to be removed.

Docs: http://php.net/mysql_affected_rows

Thanks cereal I finally figured it out, your help is much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.