Skip to Content.
Sympa Menu

freetds - Re: [freetds] Re: Problem with using the mysql_num_rows andmysql_fetch_array

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Daniel Fazekas <fdsubs AT t-online.hu>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Re: Problem with using the mysql_num_rows andmysql_fetch_array
  • Date: Thu, 2 Jun 2005 00:52:11 +0200


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




Archive powered by MHonArc 2.6.24.

Top of Page