We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Some MySQL worries
Topic Started: Jun 4 2005, 05:52 AM (220 Views)
Fire Pheonix (PM)
Member Avatar
Too much pressure!
[ *  *  *  * ]
I have this script.

db.php
 
<?php


class db
{
   
    function connect()
    {
        $connection = @mysql_connect( 'localhost' , 'user' , 'password' );
        @mysql_select_db( 'karitane' , $connection );
    }

    function query( $qid )
    {
        @mysql_query( $qid );
        echo mysql_error();
    }


    function get_page()
    {
        global $dk;

        $sql = 'SELECT * FROM kar_pages WHERE id = '. $dk->get['id'] .'';
        $result = $this->query( $sql );

        if (!$stuff = mysql_fetch_assoc( $result ))
        {
            echo 'Error';
            echo mysql_error();
            die;
        }


        echo $stuff['pg_name'];

    }

}

?>


Anyhoo that comes up with a 'Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in P:www/karitane/classes/db.php on line 26' error.

When I change it too.

db.php
 
<?php
 
 
  class db
  {
     
      function connect()
      {
          $connection = @mysql_connect( 'localhost' , 'user' , 'password' );
          @mysql_select_db( 'karitane' , $connection );
      }
 
      function query( $qid )
      {
          @mysql_query( $qid );
          echo mysql_error();
      }

      function get_page()
      {
          global $dk;
 
          $sql = 'SELECT * FROM kar_pages WHERE id = '. $dk->get['id'] .'';
          $result = @mysql_query( $sql );
 
          if (!$stuff = mysql_fetch_assoc( $result ))
          {
              echo 'Error';
              echo mysql_error();
              die;
          }
 
 
          echo $stuff['pg_name'];
 
      }
 
  }
 
  ?>


It does work. Does anybody know why?

Thanks in advance.
Kennedy
Offline Profile Quote Post Goto Top
 
Dennis
Member
[ *  *  *  *  *  *  * ]
The @ sign just suppresses errors. It still doesn't work, it just doesn't show an error message.

On line 13:

Quote:
 
      function query( $qid )
      {
          @mysql_query( $qid );
          echo mysql_error();
      }


Is $qid defined? It's not in this file, it may be defined in another file. :ermm:

I may be wrong about this, but I think unless you call the connect function in every instance, it is isolated and won't connect. I'd advise putting the connect in a different file, and requiring it.

I don't know much about classes, I'm still learning OOP.

Quote:
 
        $sql = 'SELECT * FROM kar_pages WHERE id = '. $dk->get['id'] .'';


In this part, are you calling a $_GET['id'] array? If so, I think that might be the error. Seth or someone else would know better, but I think that's wrong.

Offline Profile Quote Post Goto Top
 
Fire Pheonix (PM)
Member Avatar
Too much pressure!
[ *  *  *  * ]
Fire Pheonix
June 4, 2005 04:52 AM
I have this script.

db.php
 
<?php


class db
{
   
    function connect()
    {
        $connection = @mysql_connect( 'localhost' , 'user' , 'password' );
        @mysql_select_db( 'karitane' , $connection );
    }

    function query( $qid )
    {
        @mysql_query( $qid );
        echo mysql_error();
    }


    function get_page()
    {
        global $dk;

        $sql = 'SELECT * FROM kar_pages WHERE id = '. $dk->get['id'] .'';
        $result = $this->query( $sql );

        if (!$stuff = mysql_fetch_assoc( $result ))
        {
            echo 'Error';
            echo mysql_error();
            die;
        }


        echo $stuff['pg_name'];

    }

}

?>


Anyhoo that comes up with a 'Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in P:www/karitane/classes/db.php on line 26' error.

When I change it too.

db.php
 
<?php
 
 
  class db
  {
     
      function connect()
      {
          $connection = @mysql_connect( 'localhost' , 'user' , 'password' );
          @mysql_select_db( 'karitane' , $connection );
      }
 
      function query( $qid )
      {
          @mysql_query( $qid );
          echo mysql_error();
      }

      function get_page()
      {
          global $dk;
 
          $sql = 'SELECT * FROM kar_pages WHERE id = '. $dk->get['id'] .'';
          $result = @mysql_query( $sql );
 
          if (!$stuff = mysql_fetch_assoc( $result ))
          {
              echo 'Error';
              echo mysql_error();
              die;
          }
 
 
          echo $stuff['pg_name'];
 
      }
 
  }
 
  ?>


It does work. Does anybody know why?

Thanks in advance.
Kennedy

When i use $this->query( $sql ); It is defining it as the $sql variable.


Offline Profile Quote Post Goto Top
 
Fire Pheonix (PM)
Member Avatar
Too much pressure!
[ *  *  *  * ]
Fixed it :)

db.php
 

<?php


class db
{

function connect()
{
  $connection = mysql_connect( 'localhost' , 'user' , 'password' );
  mysql_select_db( 'karitane' , $connection );
}

function query( $qid )
{
  return mysql_query( $qid );
  echo mysql_error();
}

function get_array( $qid )
{
  return mysql_fetch_array( $qid );
}

function get_page()
{
  global $dk;

  $sql = 'SELECT * FROM kar_pages WHERE id = '. $dk->get['id'] .'';
  $result = $this->query( $sql );

  if (!$stuff = $this->get_array( $result ))
  {
  echo 'why does you mullet it up?';
  echo mysql_error();
  die;
  }


  echo $stuff['pg_name'];

}

}

?>


I had to use return!

Thanks.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply