SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chapter 4 Pg 118-123 HELP!!!!

    Hi,

    Following php & mysql SP book 4th edition.

    Seems I cannot figure this out:
    PHP Code:
    <?php
        
    $link 
    mysqli_connect('127.0.0.1''root''thewordyoucannot4get=password');
        
        if (!
    $link)
            {
                
    $output 'test to see MySQL server.';
                include 
    'output.html.php';
                exit();
            }    
        
        if (!
    mysql_set_charset(!$link'utf8'))
            {
                
    $output 'test to see MySQL server.';
                include 
    'output.html.php';
                exit();
            } 
            
            if (!
    mysqli_select_db($link'ijdb'))
            {
                
    $output 'test to see MySQL server.';
                include 
    'output.html.php';
                exit();
            }
                    
                
    $output 'test to see MySQL server.';
                include 
    'output.html.php';        
        
                
    mysqli_close($link);
        
            
    ?>
    This code produces the error:
    Warning: mysql_set_charset() [function.mysql-set-charset]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for '2.0/no DST' instead in C:\Apache2\htdocs\php\learn\index.php on line 12

    Warning: mysql_set_charset() expects parameter 2 to be resource, string given in C:\Apache2\htdocs\php\learn\index.php on line 12
    test to see MySQL server.
    Localhost
    Apche 2.2.1.4
    PHP: 5.3
    MySQL: 5.1.42

    enabled everything according to the book.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    To avoid this warning either:

    -- Suppress warning messages by changing your error reporting level

    -- Do as the warning says, and edit your php.ini to specify the server's time zone

    -- Do as the warning says, and call date_default_timezone_set

    -- Not call mysql_set_charset at all -- set the character set in your MySQL configuration instead of in your PHP code

    Also

    PHP Code:
        if (!mysql_set_charset(!$link'utf8')) 
    This line you copied wrong from the book, you don't want the negation (!) of the link resource variable

    Hope that helps

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    will try when I get home thanks Dan & let u kno if it works

  4. #4
    SitePoint Zealot atetlaw's Avatar
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys,
    This warning (not an error) occurs because of a change in PHP 5.3 which came out after the book. It's also mentioned on the errata page. It's the one that begins "As of PHP 5.3, the date function requires that a timezone be specified."
    http://www.sitepoint.com/books/phpmysql4/errata.php

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Getting Warning now: Warning: mysql_set_charset() expects parameter 1 to be string, object given
    Unable to Connect.
    line 12

    & have edited php.ini & included timezone

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed

  7. #7
    SitePoint Zealot atetlaw's Avatar
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh! What was the solution?

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Two typos were on that line -- mysql_set_charset instead of mysqli_set_charset (which take parameters in opposite order resulting in that warning), and a negation operator (!) in front of $link.

  9. #9
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    silly me

  10. #10
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but thanks for help guys & the book is very well written & learning even if I make mistakes.....


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
  •