mysql help

Associate
Joined
1 Mar 2006
Posts
425
trying to get a irc roomlist on my webpage

using below script from net

Code:
<?php 
    /** 
      *    server configuration 
      */ 
    define ('IRC_SERVER', 'irc.xxx.net); 
    define ('IRC_PORT', 6667); 
    define ('IRC_REFRESH', 1);        // minutes 

    /** 
      *    DB Tables 
      */ 
    define ('T_CONFIG', 'irc_config'); 
    define ('T_CHANNEL', 'irc_channel'); 

    /** 
      *    connect to database 
      */ 
    mysql_connect ("xxxxxxxx", "xxxxxx", "xxxx"); 
    mysql_select_db ("irc"); 

    /** 
      *    uncomment to create tables on first run 
      */ 
//    create_tables (); 

    /** 
      *    get channels and output 
      */ 
    $arr_channels        =    db_get_channels (); 
    foreach ($arr_channels as $arr_channel) 
    { 
        echo join ("<br>n", $arr_channel); 
        echo "-----------------<br>n"; 
    } 


    /** 
      *    db_get_channels 
      *    - return list of all channels either by asking database or IRC Server 
      */ 
    function db_get_channels () 
    { 
        /** 
          *    get last update timestamp 
          */ 
        $raw            =    mysql_query ("SELECT UNIX_TIMESTAMP(lastupdate) FROM ".T_CONFIG); 
        list ($ts_lastupdate)    =    mysql_fetch_row ($raw); 
        mysql_free_result ($raw); 

        /** 
          *    too old? 
          */ 
        if ($ts_lastupdate < (time() - (60*IRC_REFRESH))) 
        { 
            /** 
              *    block parallel processing by updating lastupdate to current time 
              */ 
            mysql_query ("REPLACE INTO ".T_CONFIG." (lastupdate) VALUES (NOW())"); 

            /** 
              *    get channels 
              */ 
            if (($arr_channels = irc_get_channels ()) == false) 
            { 
                /** 
                  *    failed, return with db-source 
                  */ 
                return db_get_channels (); 
            } 

            /** 
              *    clear existing list 
              */ 
            mysql_query ("TRUNCATE ".T_CHANNEL); 


            /** 
              *    insert channels into database 
              */ 
            reset ($arr_channels); 
            $arr_insert[]        =    array (); 
            foreach ($arr_channels as $str_channel => $arr_data) 
            { 
                $arr_insert[]        =    "('".mysql_escape_string($str_channel)."', ".intval($arr_data[0]).", '".mysql_escape_string ($arr_data[1])."')"; 

                if (sizeof ($arr_insert) > 25) 
                { 
                     mysql_query ("INSERT INTO ".T_CHANNEL." (channel, users, topic) VALUES ".join(',', $arr_insert)); 
                    unset ($arr_insert); 
                } 

                $arr_return[]        =    array ($str_channel, $arr_data[0], $arr_data[1]); 
            } 
            unset ($arr_channels); 

            /** 
              *    some entries left? 
              */ 
            if (sizeof ($arr_insert)) 
            { 
                mysql_query ("INSERT INTO ".T_CHANNEL." (channel, users, topic) VALUES ".join(',', $arr_insert)); 
            } 
            unset ($arr_insert); 
        } 
        /** 
          *    get input from DB 
          */ 
        else 
        { 
            $raw        =    mysql_query ("SELECT channel, users, topic FROM ".T_CHANNEL); 
            while ($arr_return[] = mysql_fetch_assoc ($raw)) 
            { /* hi there :) */ } 
            mysql_free_result ($raw); 
        } 

        /** 
          *    return arary of channels 
          *        [0]    =    #channel 
          *        [1]    =    users 
          *        [2]    =    topic 
          */ 
        return $arr_return; 
    } 
    /**    <- end of db_get_channels () */ 


    /** 
      *    irc_get_channels 
      *    - connects to IRC Server and returns a multidimensional array of all channels 
      */ 
    function irc_get_channels () 
    { 
        /** 
          *    open socket to server 
          */ 
        $hwnd_irc        =    fsockopen (IRC_SERVER, IRC_PORT); 

        /** 
          *    connection failed? 
          */ 
        if (!$hwnd_irc) 
            return false; 

        /** 
          *    use random nick & identification 
          */ 
        $str_nick        =    chr(rand(65,90)).time().rand(1,10000); 
        fputs ($hwnd_irc, "USER ".$str_nick." ".IRC_SERVER." ".IRC_SERVER." :Channelreaderrn"); 
        fputs ($hwnd_irc, "NICK ".$str_nick."rn"); 

        /** 
          *    get data until we're finally connected & verified 
          */ 
        $arr_channels        =    array (); 
        while (!feof($hwnd_irc)) 
        { 
            $str_line    =    fgets ($hwnd_irc, 1024); 

            /** 
              *    response to PING requests 
              */ 
            if (substr($str_line,0,5) == 'PING ') 
                fputs ($hwnd_irc, "PONG ".trim(array_pop(explode(':', $str_line)))."rn"); 

            /** 
              *    switch between response ID's 
              */ 
            $arr_line    =    explode(' ', $str_line); 
            switch ($arr_line[1]) 
            { 
                /** 
                  *    "End of Motd" (376) 
                  */ 
                case 376: 
                    /** 
                      *    send LIST request 
                      */ 
                    fputs ($hwnd_irc, "LISTrn"); 
                    break; 

                /** 
                  *    channel list 
                  */ 
                case 322: 
                    /** 
                      *    0 = sender 
                      *    1 = ID 
                      *    2 = target 
                      *    3 = channels name 
                      *    4 = users in channel 
                      */ 
                    $arr_channels[$arr_line[3]]    =    array (); 
                    $arr_channels[$arr_line[3]][0]    =    $arr_line[4]; 
                    $arr_channels[$arr_line[3]][1]    =    trim (substr ($str_line, strpos($str_line, ':', 5))); 
                    break; 

                /** 
                  *    End of List 
                  */ 
                case 323: 
                    fputs ($hwnd_irc, "QUITrn"); 
                    break 2; 
            } 
        } 
        fclose ($hwnd_irc); 

        /** 
          *    got no list? 
          */ 
        if (!sizeof ($arr_channels)) 
            return false; 

        /** 
          *    return hash of all channels 
          *        [#channel] 
          *    with an array of users & topic 
          *        [0]        =    users 
          *        [1]        =    topic 
          */ 
        return $arr_channels; 
    } 
    /**    <- end of irc_get_channels () */ 




    /** 
      *    create_tables 
      *    - create table structure 
      */ 
    function create_tables () 
    { 
        $arr_query[]        =    "DROP TABLE IF EXISTS `irc_channel`"; 
        $arr_query[]        =    "CREATE TABLE `irc_channel` ( 
                  `channel` varchar(32) NOT NULL default '', 
                  `users` smallint(5) unsigned NOT NULL default '0', 
                  `topic` varchar(255) NOT NULL default '', 
                  PRIMARY KEY  (`channel`) 
                ) TYPE=MyISAM"; 

        $arr_query[]        =    "DROP TABLE IF EXISTS `irc_config`"; 
        $arr_query[]        =    "CREATE TABLE `irc_config` ( 
                  `lastupdate` datetime NOT NULL default '0000-00-00 00:00:00' 
                ) TYPE=MyISAM"; 

        foreach ($arr_query as $str_query) 
            mysql_query ($str_query); 

    } 
    /**    <- end of create_tables () */ 
?>
i cant get it too connect..think its because of the mysql_connect ("localhost", "login", "password");

part

all database user and passes are correct and stuff

get the below response.
Code:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'denbyuk@locahost' (1) in /home2/denbyuk/public_html/channels.php on line 18

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'denbyuk'@'localhost' (using password: NO) in /home2/denbyuk/public_html/channels.php on line 19

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home2/denbyuk/public_html/channels.php on line 19

Warning: mysql_query() [function.mysql-query]: Access denied for user 'denbyuk'@'localhost' (using password: NO) in /home2/denbyuk/public_html/channels.php on line 46

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home2/denbyuk/public_html/channels.php on line 46

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/denbyuk/public_html/channels.php on line 47

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home2/denbyuk/public_html/channels.php on line 48

Warning: mysql_query() [function.mysql-query]: Access denied for user 'denbyuk'@'localhost' (using password: NO) in /home2/denbyuk/public_html/channels.php on line 58

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home2/denbyuk/public_html/channels.php on line 58

so on..

please HELP! lol
 
Errrrrrrrrrrr you might want to read the error properly, it might help (you never know).

Either change to just 'localhost' or give your user the necessary privileges.
 
Back
Top Bottom