You are here: Re: problems with mysql_fetch_array($IsResult,MYSQL_NUM) « PHP Programming Language « IT news, forums, messages
Re: problems with mysql_fetch_array($IsResult,MYSQL_NUM)

Posted by purcaholic on 05/28/07 09:01

On 28 Mai, 09:55, Patrick <hornep...@gmail.com> wrote:
> Hi
>
> I am trying to write a simple database class to encapsulate all the
> database functions in one. Howerver I am having problems with
> while($row = mysql_fetch_array($IsResult,MYSQL_NUM)) line it never
> executes the loop. $IsResult is reeves no value.
>
> What am I doing wrong
>
> Thanks
>
> pat
>
> <?php
>
> class CDatabase
> {
> // Database
> var $misOpen = false;
> var $mResult;
>
> function getResults()
> {
> return $this->mResult;
> }
>
> function isOpen()
> {
> return $this->misOpen;
> }
>
> // constructer
> function CDatabase($username,$password,$host,$databasename)
> {
> $db_connection = mysql_connect($host,$username,$password);
> $this->misOpen = false;
>
> if($db_connection)
> {
> $this->misOpen = true;
> mysql_select_db($databasename);
> }
>
> echo mysql_error();
> }
>
> function __destruct()
> {
> $this->disconnect();
> }
>
> function disconnect()
> {
> if ($this->isOpen())
> {
> mysql_close();
> }
> }
>
> function sqlQuery($query)
> {
> $numberofResults = 0;
> $IsResult = mysql_query($query);
>
> echo "IsResult= '".$IsResult."' <br/>\n";
>
> while($row = mysql_fetch_array($IsResult,MYSQL_NUM))
> {
> $this->mResult[] = $row;
> $numberofResults++;
> echo $numberofResults++;
> echo "loop";
> }
>
> return $numberofResults;
> }
>
> };
>
> ?>


Your class seems to work (but i haven't tested it).

I suppose the passed query is invalid. And an try{}catch{} block to
your sqlQuery function and throw an error, if mysql_query fails.

Tip:
You increment the $numberofResults counter twice ("$numberofResults++"
and "echo $numberofResults++"), once is enough.
Use __construct() instead of CDatabase().

purcaholic

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация