PHP4 and this function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon

    #1

    PHP4 and this function

    function query($query, $return = false)
    {
    $fetch = mysql_query($qu ery, $this->connection) or
    die2(mysql_erro r($this->connection)) ;
    if($return)
    return $fetch;
    }

    mysql_error(): supplied argument is not a valid MySQL-Link resource

    the line that begins with $fetch is my problem. This was originally a
    PHP5 script that I am retrofitting.
    The $query is used all over, and it is really gumming things up.


    Thanks!
    jon

  • ming

    #2
    Re: PHP4 and this function

    I think it the -> problem. php5 class is different with php4 class

    Jon wrote:[color=blue]
    > function query($query, $return = false)
    > {
    > $fetch = mysql_query($qu ery, $this->connection) or
    > die2(mysql_erro r($this->connection)) ;
    > if($return)
    > return $fetch;
    > }
    >
    > mysql_error(): supplied argument is not a valid MySQL-Link resource
    >
    > the line that begins with $fetch is my problem. This was originally a
    > PHP5 script that I am retrofitting.
    > The $query is used all over, and it is really gumming things up.
    >
    >
    > Thanks!
    > jon
    >[/color]

    Comment

    • Tony Marston

      #3
      Re: PHP4 and this function


      "ming" <myhusky@gmail. com> wrote in message
      news:vEWAf.9838 $43.6013@nnrp.c a.mci.com!nnrp1 .uunet.ca...[color=blue]
      >I think it the -> problem. php5 class is different with php4 class[/color]

      No, this works in both PHP 4 and 5 as I use it all the time.
      [color=blue]
      > Jon wrote:[color=green]
      >> function query($query, $return = false)
      >> {
      >> $fetch = mysql_query($qu ery, $this->connection) or
      >> die2(mysql_erro r($this->connection)) ;
      >> if($return)
      >> return $fetch;
      >> }
      >>
      >> mysql_error(): supplied argument is not a valid MySQL-Link resource
      >>
      >> the line that begins with $fetch is my problem. This was originally a
      >> PHP5 script that I am retrofitting.
      >> The $query is used all over, and it is really gumming things up.[/color][/color]

      Ths function can only be used in an object as $this->connection refers to a
      property called $connection within the current object. Have you checked to
      see if $this->connection actually refers to a valid resource? Where did the
      previous call to mysql_connect() store its result?

      --
      Tony Marston
      This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

      [color=blue][color=green]
      >> Thanks!
      >> jon
      >>[/color][/color]


      Comment

      • Jon

        #4
        Re: PHP4 and this function

        On 2006-01-22 21:50:34 -0600, "Tony Marston" <tony@NOSPAM.de mon.co.uk> said:
        [color=blue]
        >
        > "ming" <myhusky@gmail. com> wrote in message
        > news:vEWAf.9838 $43.6013@nnrp.c a.mci.com!nnrp1 .uunet.ca...[color=green]
        >> I think it the -> problem. php5 class is different with php4 class[/color]
        >
        > No, this works in both PHP 4 and 5 as I use it all the time.
        >[color=green]
        >> Jon wrote:[color=darkred]
        >>> function query($query, $return = false)
        >>> {
        >>> $fetch = mysql_query($qu ery, $this->connection) or
        >>> die2(mysql_erro r($this->connection)) ;
        >>> if($return)
        >>> return $fetch;
        >>> }
        >>>
        >>> mysql_error(): supplied argument is not a valid MySQL-Link resource
        >>>
        >>> the line that begins with $fetch is my problem. This was originally a
        >>> PHP5 script that I am retrofitting.
        >>> The $query is used all over, and it is really gumming things up.[/color][/color]
        >
        > Ths function can only be used in an object as $this->connection refers
        > to a property called $connection within the current object. Have you
        > checked to see if $this->connection actually refers to a valid
        > resource? Where did the previous call to mysql_connect() store its
        > result?[/color]


        function constructor($ho st, $user, $pass, $database)
        {

        $this->connection = mysql_connect($ host, $user, $pass) or die2

        This was modified from a more PHP5 compatible __constructor, and
        function cnstructor allowed it to "work" apparently, but not as well as
        I need it to.

        jon

        Comment

        • NC

          #5
          Re: PHP4 and this function

          Jon wrote:[color=blue]
          > "Tony Marston" <tony@NOSPAM.de mon.co.uk> said:
          >[color=green]
          > > Ths function can only be used in an object as $this->connection refers
          > > to a property called $connection within the current object. Have you
          > > checked to see if $this->connection actually refers to a valid
          > > resource? Where did the previous call to mysql_connect() store its
          > > result?[/color]
          >
          > function constructor($ho st, $user, $pass, $database)
          > {
          >
          > $this->connection = mysql_connect($ host, $user, $pass) or die2
          >
          > This was modified from a more PHP5 compatible __constructor, and
          > function cnstructor allowed it to "work" apparently, but not as well as
          > I need it to.[/color]

          In PHP 4, the consturctor has the same name as the class. So your
          constructor() function is probably never executed.

          Cheers,
          NC

          Comment

          Working...