tags:

views:

77

answers:

3

Below is some PHP code that i have written, the problem occurs when it gets to the use of the num_of_rows(), it just does not seem to work and i cant figure out why?

<?php
try
{
    $divMon_ID = array();
    $divMon_Position = array();
    $divMon_Width = array();
    $divMon_Div = array();

    $db = new PDO('sqlite:db/EVENTS.sqlite');
    $result_mon = $db->query('SELECT * FROM Monday');
    $totalRows = mysql_num_rows($result_mon);
    //for($counter=1; $counter<=10; $counter+=1)
    //{

        //<div id="event_1" style="position:absolute; left: 0px; top:-39px; width:100px; font-family:Arial, Helvetica, sans-serif; font-size:small; border:2px blue solid; height:93px">
        //$divMon_ID[]=$row['Id'];
        //$divMon_Position[]=$row['Origin'];
        //$divMon_P[]=$row['Position'];
    //}
}
catch(PDOException $e)
{
    print 'Exception : '.$e->getMessage();
}

?>

I know that it is the "$totalRows = mysql_num_rows($result_mon);" statement because when i then comment it out, the page can load.

Am i using the function in the wrong way?

Thanks.

+1  A: 

You cant use mysql_num_rows with pdo. You have to use rowCount()

Galen
+1  A: 

Mysql_num_rows would work if you used mysql_connect, and other mysql_* functions. As you are using PDO, you have to use PDO's methods, like rowCount()

Clement Herreman
A: 

You've created a PDO object connecting to an SQLite database. Why should a MySQL function know how to deal with any of that?

The query method returns an object of type PDOStatement, which has a rowCount method. Use that:

$totalRows = $result_mon->rowCount();

That is, if you even need to know the total number of rows before you process them. If all you need to know is the number of rows in the table, consider using the COUNT SQL function instead: SELECT COUNT(*) FROM Monday.

Rob Kennedy