[freetds] Re: Problem with using the mysql_num_rowsandmysql_fetch_array

Max Eaves max.eaves at bbc.co.uk
Wed Jun 1 18:55:49 EDT 2005


Hi Daniel,

Sorry - dyslexia - I missed the one character difference!  

Mssql and mysql looked very simular.  I will go away now!  

Thanks for your help.

Max

-----Original Message-----
From: freetds-bounces at lists.ibiblio.org
[mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of Daniel Fazekas
Sent: 01 June 2005 23:52
To: FreeTDS Development Group
Subject: Re: [freetds] Re: Problem with using the
mysql_num_rowsandmysql_fetch_array



On Jun 1, 2005, at 23:26, Max Eaves wrote:

> $result = mssql_query ($sql, $con) or die (mysql_error()); 
> $numberofrows = mysql_num_rows($result); echo "The number of rows are 
> $numberofrows";
>
> You get the error message: WARNING:mysql_num_rows():Supplied
> Resource is
> not a valid Result Resource in /var/www/xxx/xxx at line x
>
> I wish I understood what the error message meant.
> I get the same error message when I start introducing
> while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

Uh. What I was trying to explain is that you should quit trying to  
use mysql_ functions for MSSQL, as they were meant to interface with  
a totally different database system.
That's like insisting on speaking French to someone who only speaks  
English.

mysql is not equal to mssql and not even similar. See that one letter  
of difference? m*Y*sql versus m*S*sql.

You're in luck though as the PHP functions for mysql and mssql are  
very similar, again mostly only a single letter separating the two.

So, you could just change:
mysql_num_rows to mssql_num_rows
mysql_fetch_array($result, MYSQL_ASSOC) to mssql_fetch_assoc($result)
mysql_error to mssql_get_last_message

See http://www.php.net/manual/en/ref.mssql.php for the rest.

> It seems that when I introduce the '@' sign onto mysql_fetch_array and

> to mysql_num_rows, I get a blank result.  Very odd indeed.

That too isn't odd at all. The @ sign instructs PHP to omit any  
warning/error messages caused by the function.
See http://www.php.net/manual/en/language.operators.errorcontrol.php

Use it only if a call is normal and expected to fail and nobody  
should know.
It's a common bad practice for many beginner php programmers to  
overuse @ and suppress any and all messages, making finding problems  
a lot harder, when what they should be doing is turning  
display_errors Off once their code is deployed in a production  
environment.

The PHP Manual is your friend.

--
fds
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds

http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system. 
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received. 
Further communication will signify your consent to this.


More information about the FreeTDS mailing list