SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ?? String value = mysqli_select_db() ??

    Is it really necessary to assign a string value to mysqli_select_db()?
    When I started learning to use PHP with MySQL many text book examples would show something like:

    $DBSelect = mysqli_select_db($connect, 'mydbname');

    Often $db was use, but regardless of what the variable was named, it is never referred to again in any example code I have studied and I have not yet used it else where in my code. I see no need to have this function assigned to a variable. I have started using it in my code without making an assignment, like:

    mysqli_select_db($connect, 'mydbname');

    Is there any good programing reason for the other method?

    Sam
    ;

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysqli_select_db returns either true on success or false on failure. You only need to assign a variable to its result if you need that information for later.

    i see most people using this instead

    Code PHP:
    if (mysqli_select_db('db')) {
        // do something
    }

  3. #3
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can not think of any reason the variable would be needed again. Thanks for confirming what I thought.


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
  •