By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

num_rows

P: 15
Hi,

i have a code which is used to connect to database and get number of rows affteced from the SQL Query.
when i run the query connecting to postgres DB it gives num_row as 0, but when i run the query connecting to mssql server DB it gives num_row as -1. Below is my code.

$conn = odbc_connect('server','username','password');
$sql = "SELECT * FROM clients WHERE client_code='*'";

$result = odbc_exec($conn, $sql);
$num_rows = odbc_num_rows($result);
echo "num of rows :".$num_rows;

Kindly suggest
Feb 6 '07 #1
Share this Question
Share on Google+
8 Replies


ronverdonk
Expert 2.5K+
P: 4,258
You cannot get a number of rows from a connect statement.

As far as your query is concerned, you probably have an error. It is good practice to test the result of queries after each execution. So you would get more information when you code it like this:
[php]
$conn = odbc_connect('server','username','password')
or die("Connect error: ".odbc_errormsg());

$sql = "SELECT * FROM clients WHERE client_code='*'";
$result = odbc_exec($conn, $sql)
or die("SELECT error: ".odbc_errormsg());

$num_rows = odbc_num_rows($result);
echo "num of rows :".$num_rows;
[/php]
Ronald :cool:
Feb 6 '07 #2

P: 15
Hi,
i have tested the query but no results again. I get the same.

Regards
Feb 7 '07 #3

P: 1
Bou
Hi,
i have tested the query but no results again. I get the same.

Regards
Try "\*" in the query instead of "*".
Feb 7 '07 #4

P: 15
Hi,

I get differenet errors.
[PHP]Warning: Unexpected character in input: '\' (ASCII=92) state=1 in c:\Inetpub\wwwroot\dev\lib\login_functions.php on line 399

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at c:\Inetpub\wwwroot\dev\lib\login_functions.php:399 ) in c:\Inetpub\wwwroot\dev\lib\login_functions.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at c:\Inetpub\wwwroot\dev\lib\login_functions.php:399 ) in c:\Inetpub\wwwroot\dev\lib\login_functions.php on line 2

client selection sql :0
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '0'., SQL state 37000 in SQLExecDirect in c:\Inetpub\wwwroot\dev\lib\login_functions.php on line 401

Warning: odbc_num_rows(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\dev\lib\login_functions.php on line 402[/PHP]
Feb 7 '07 #5

P: 15
Hi Friends,

I got working, have one strange problem the if conditions are not working, it is not supporting at all. Any idea why ?

Regards
Feb 8 '07 #6

Motoma
Expert 2.5K+
P: 3,235
Hi Friends,

I got working, have one strange problem the if conditions are not working, it is not supporting at all. Any idea why ?

Regards
Not quite sure what you mean by that.
Reword your question and I'll see if I can tell you what's going on.
Feb 8 '07 #7

P: 15
Hi,

[PHP] $sql = "SELECT * FROM users WHERE LOWER(username)='" . strtolower($username) . "' AND (client_code='*' or client_code='$client_code')";
$result = odbc_exec($conn, $sql);

while($row = odbc_fetch_array($result))
{
$active = $row['active'];
$pwd = $row['password'];
}

echo "data is :".$active;[/PHP]

iam getting the value of the variable $active however if we use the same with below code.

[PHP] if ($row = odbc_fetch_row($result) > 0)
{
$active = $row['active'];
$pwd = $row['password'];
}
echo "data is :".$active;[/PHP]


This doesn't work

Regards
Feb 9 '07 #8

Motoma
Expert 2.5K+
P: 3,235
Hi,

[PHP] $sql = "SELECT * FROM users WHERE LOWER(username)='" . strtolower($username) . "' AND (client_code='*' or client_code='$client_code')";
$result = odbc_exec($conn, $sql);

while($row = odbc_fetch_array($result))
{
$active = $row['active'];
$pwd = $row['password'];
}

echo "data is :".$active;[/PHP]

iam getting the value of the variable $active however if we use the same with below code.

[PHP] if ($row = odbc_fetch_row($result) > 0)
{
$active = $row['active'];
$pwd = $row['password'];
}
echo "data is :".$active;[/PHP]


This doesn't work

Regards
That is because $row is an array, and I have no idea how it compares to 0.

What you probably want to do is this:
[PHP]
if (count($row = odbc_fetch_row($result)) > 0)
{
$active = $row['active'];
$pwd = $row['password'];
}
echo "data is :".$active;
[/PHP]
Feb 9 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.