Results 1 to 2 of 2

Thread: [RESOLVED] Undefined Variable

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Resolved [RESOLVED] Undefined Variable

    Sorry to ask this n00b question.
    It's just my 2nd day in php.

    I have this class database connection:
    PHP Code:
    <?php
    class DBConnection{

    private 
    $link;

    public function 
    connect(){
    include 
    'connstring.php';
    $link mysql_connect($host,$user,$pw);
    if(!
    $link)
    {
        die(
    'Could not connect'.mysql_error());
    }
    }

    public function 
    close()
    {
        
    mysql_close($link);
    }
    }
    ?>
    But when I call connect and close function the errors come out.
    Notice: Undefined variable: link in C:\Program Files\Apache Group\Apache2\htdocs\connection.php on line 16

    Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Group\Apache2\htdocs\connection.php on line 16
    why?

    edit: using
    PHP Code:
    $this->link 
    do the trick.
    Last edited by mar_zim; Feb 18th, 2006 at 04:11 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] Undefined Variable

    Have you seen the article in my sig about PHP 5 OOP? I have made a database wrapper example there. You may find it useful, even if your script isn't in PHP 5.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width