Results 1 to 4 of 4

Thread: Multiple queries on one mysqli object?

  1. #1
    Join Date
    Apr 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Multiple queries on one mysqli object?

    I'm still new to MySQL/PHP. The book I've ordered hasen't arrived yet, and I am eager to learn. :P

    Now, here's the problem:

    Is it possible to have multilpe queries on one mysqli object?

    I found some code, and tried amending it, but it doesn't work.
    I get Fatal error: Call to a member function query() on a non-object in /home/.mohave/tetest/<mysite>/ex/table2b.php on line 35
    which leads me to believe that the "object" somehow closes connection with the db after one query.
    Also, with my setup I cannot use $result.close() to "release" the connection.

    Code:
    $connect = new mysqli("....")
    
    $query = "SELECT
          * ..."
    
    $result = $connect->query($query)
    
    function f1() {
    
         $query_a = "SELECT.."
         $results_a =  $connect->query($query_a)   <-- line 35
            ..do something...
    }
    
    function f2() {
    
         $query_b = "SELECT.."
         $results_b =  $connect->query($query_b)
            ..do something...
    }
    
    while($row = $result->fetch_array(MYSQLI_ASSOC))
    {
        f1(some parameter from $row)
        f2(another parameter from $row)
        ...do something more...
    }

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Make sure that you are connected to the database properly before executing any queries. Here is a step-by-step tutorial about the PHP-MySql interaction

    http://www.php-mysql-tutorial.com/

  3. #3
    Join Date
    Apr 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I'm quite sure I am connected b/c the first query doesn't yield any errors, and I'm also able to get a quantitative response (I'm able to get num_rows).

  4. #4
    Join Date
    Apr 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I've partly figured it out.
    It's a question of scope.
    I supposedly need to globally declare variables within functions.

    http://www.phpbuilder.com/board/show...php?t=10308946

    Well. I'm still learning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •