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: "Max Eaves" <max.eaves AT bbc.co.uk>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Re: Problem with using the mysql_num_rows andmysql_fetch_array
  • Date: Wed, 1 Jun 2005 22:26:01 +0100


Hi there,

Thank you for those kind words, however, I am still stuck with the same
error message.

I proved that I correctly connecting to the database using tsql, and by
executing some basic SQL commands,
I have manged to get the database to cough up the correct values. The
database in question is a Microsoft SQL2000 server. I am using TDS
protocol 8.0 [the same results from using TDS protocol 7.0]

This is going to be a longesh email, but I REALLY want to try and get to
nub of this fault.

My code for programme 105.php looks as follows:

<html>
<body>
<?php
$con = mssql_connect ("x.x.x.x", "sa", "apassword");
mssql_select_db ("PreSetLive", $con);
$sql = "SELECT * FROM PST_Channels";
$result = mssql_query ($sql, $con) or die (mysql_error());
echo "The information from the server is: ";
echo mssql_result ($result, 0, 0);
echo mssql_result ($result, 1, 0);

mssql_close ($con);
?>
</body>
</html>

This programme runs correctly; it outputs some entries from the
database, however when you introduce

$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)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

Warning:mysql_fetch_array(): Supplied Resource is not a valid Result
Resource in /var/www/xxx/xxx at line x

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.

Has anybody experienced this kind of problem before?


Best Wishes



Max

On May 29, 2005, at 22:40, max wrote:

> I am running a local Fedora Core 3 box with FreeTDS / PHP and
> Apache. I
> have successfully set up, configured FreeTDS, PHP (with graphic
> support)
> and Apache (with PHP support) using the book SAM PHP, MySQL and Apache
> book (sadly slightly out of date - as it references PHP4 instead of
> PHP5).


>In PHP, you use the mssql extension to access it, with function names
>starting with mssql_

>This is what you need FreeTDS for. If you're trying to talk to a
>Microsoft SQL server running on a Windows machine from another
>computer which is *not* running Windows, you need FreeTDS and you are
>- mostly - in the right place.

> In essence, I want to assume a couple of things - FreeTDS translates
> mysql_fetch_array() and mysql_num_rows() when looking up
> information in
> the database.

>FreeTDS has absolutely nothing to do with those mysql_ functions.
>Just switch them to mssql_ and things should work -- looking at the
>list of functions you are trying to use, I think only mysql_error
>won't have a direct mssql_error equivalent.

> I did have a look at the API's on the FreeTDS site, but
> was slightly confused over what I should be using.

>Having successfully installed FreeTDS for use with PHP, the FreeTDS
>manual should be quite unnecessary for you now. You even appear to
>have successfully connected to the database.

>Going from there, it's the PHP Manual and its pages describing the
>MSSQL extension you should be reading:

http://www.php.net/mssql

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.




Archive powered by MHonArc 2.6.24.

Top of Page