I'm trying to get a small PHP based log reader to run but get this error every time:

Fatal error: Call to undefined function: mysql_connect() in 
/var/www/html/weblog/weblog.php on line 58

Here is the PHP I'm using ... does anyone know what is happening here?

<?php
/*
Simple syslog web viewer
by NDG Tech team - www.ndgtech.ro.

version: 0.5.1

Authors: Adrian Badea <adi [at] ndgtech.ro>
         Radu Solea <radu [at] ndgtech.ro>
Contributor: Hannes Gruber <hannes [at] usw.at>

Tested with:
            Apache 2.0.36
            PHP 4.3.0
            MySQL 3.23.51
            Slackware Linux 8.1
            kernel version 2.4.20
            on an AthlonXP 1800+ 512 MB SDRAM
*/

error_reporting(E_ERROR+E_WARNING);
$configuration=parse_ini_file('weblog.ini');

function htmlerror()
{
echo "<html><head><title>Error page</title></head>";
echo "<body><br><br><br><br><font size=4><b>WebLog error<br></b><hr size=1 width=62% 
align=left>";
echo "This program has performed an illegal operation. Software police has been 
notified.</hr><br><br>";
echo "</font></body></html>";
exit;
}


if (($_POST["user"]!=NULL) && ($_POST["pass"]!=NULL))
        {
        setcookie("user",$_POST["user"],time()+3600);
        setcookie("pass",$_POST["pass"],time()+3600);
        $username=$_POST["user"];
        $password=$_POST["pass"];
        }
        elseif (($_COOKIE["user"]!=NULL) && ($_COOKIE["pass"]!=NULL))
                {
                $username=$_COOKIE["user"];
                $password=$_COOKIE["pass"];
                }
                else
                    {
                    htmlerror();
                    };


function getmicrotime(){                // code from the PHP manual
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }
$time_start = getmicrotime();

mysql_connect("loghost:3306",$username,$password);

if (mysql_errno()!=0)
    {
      echo "Mysql error:&nbsp;";
      $error=mysql_error();
      echo $error;
      exit;
    }

mysql_select_db("system");              // previously created database

$create_query="create temporary table filenames (name varchar(255) unique, sep 
varchar(255))";
$p1=mysql_query($create_query);

$load_query="load data infile '".$configuration['config_file']."' into table filenames 
fields terminated by '\t';";
$p2=mysql_query($load_query);

if ($_POST["lo"]==NULL)
                        {
                        $file_get="select * from filenames limit 1";
                        $result=mysql_query($file_get);
                        $row=mysql_fetch_array($result);
                        $filename=$row["name"];
                        $separator=$row["sep"];
                        }
        else
          if ($_POST["load"]==NULL)
            {
            $filename=$_POST["fn"];
            $file_get="select sep from filenames where name='$filename'";
            $result=mysql_query($file_get);
            $row=mysql_fetch_array($result);
            $separator=$row["sep"];
            }
if ($_POST["load"]!=NULL)
                        {
                        $filename=$_POST["files"];
                        $file_get="select sep from filenames where name='$filename'";
                        $result=mysql_query($file_get);
                        $row=mysql_fetch_array($result);
                        $separator=$row["sep"];
                        $lo_val=0;
                        $hi_val=15;
                        $esearch=NULL;
                        $vsearch=NULL;
                        }


/**
$filepath=dirname($filename)."/";
$file=basename($filename);
exec("find $filepath -name '$file*' -type f -print0 | xargs -ifile -0 cat 'file' >> 
/tmp/mesaje");
 */
exec("cp $filename /tmp/mesaje");
exec("chmod 444 /tmp/mesaje");

$hostname=exec('echo ${HOSTNAME%%.*}');

mysql_query("create temporary table syslog (date varchar(16), message varchar(255))");
$query="load data infile '/tmp/mesaje' into table syslog fields terminated by ' 
$separator '";

mysql_query($query);

if (($_POST["vsearch"]!=NULL) || ($_POST["search"]!=NULL))
                {
                $pula=$_POST["vsearch"];
                $query="select COUNT(*) from syslog where message like '%$pula%'";
                }
        else
                {
                $query="select COUNT(*) from syslog";
                }

$res=mysql_query($query);
$maximum=mysql_fetch_row($res);
$maximum=$maximum[0];

echo "<head><title>Syslogd web viewer</title></head>";

echo "<center>";
echo "<body text=\"#000000\" bgcolor=\"#F2EAEA\"><b><font size=12>";

echo "<table border=0 align=center cellpadding=5>";
echo "<tr bgcolor=\"#9db3cc\" align=center width=60% height=10><td><font 
size=5><b>WebLog - Syslogd Web Viewer</b></font></td></tr>";
echo "</table>";
echo "</font><br></center></body></b>";
echo "<body bgcolor=\"C0C0C0\">";

if ($_POST["lo"]==NULL)
                {
                $lo_val=0;
                $hi_val=15;
                }
elseif ($_POST["hi"]==NULL)
                {
                $lo_val=0;
                $hi_val=15;
                }
else if ($_POST["next"]!=NULL)
                {
                $lo_val=$_POST["hi"];
                $hi_val=2*$_POST["hi"]-$_POST["lo"];
                }
else if($_POST["prev"]!=NULL)
                {
                $lo_val=2*$_POST["lo"]-$_POST["hi"];
                $hi_val=$_POST["lo"];
                }
else if($_POST["go"]!=NULL)
                {
                $lo_val=$_POST["lo"];
                $hi_val=$_POST["hi"];
                }
else if($_POST["rst"]!=NULL)
                {
                $lo_val=0;
                $hi_val=15;
                $esearch=NULL;
                $vsearch=NULL;
                }
else if($_POST["bsearch"]!=NULL)
                {
                $lo_val=0;
                $hi_val=15;
                }
else if($_POST["esearch"]!=NULL)
                {
                $lo_val=0;
                $hi_val=15;
                }

if (($_POST["bsearch"]!=NULL) && ($_POST["search"]!=NULL))
        {
        $esearch=1;
        $vsearch=$_POST["search"];
        }
        elseif ($_POST["esearch"]!=NULL)
                {
                $esearch=$_POST["esearch"];
                $vsearch=$_POST["vsearch"];
                }
                else
                        {
                        $esearch=NULL;
                        $vsearch=NULL;
                        }

if ($_POST["load"]!=NULL)
        {
        $esearch=NULL;
        $vsearch=NULL;
        }

if ($lo_val>$hi_val)
        {
        $temp=$hi_val;
        $hi_val=$lo_val;
        $lo_val=$temp;
        }

if ($hi_val>$maximum)
        {
         if ($lo_val>=$maximum)
                    {
                    $lo_val=0;
                    $hi_val=15;
                    }
                    else
                    {
                    $hi_val=$maximum;
                    }
        }

if ($lo_val<0)
        {
        if ($hi_val<=0)
                {
                $lo_val=$maximum-15;
                $hi_val=$maximum;
                }
                else
                {
                $lo_val=0;
                }
        }



echo "<form action=\"weblog.php\" method=\"post\">";

echo "&nbsp;&nbsp;Browse database:&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=\"submit\" value=\"Prev\" name=prev>";
echo "&nbsp;&nbsp;&nbsp;";
echo "<input type=\"submit\" value=\"Next\" name=next>";
echo "&nbsp;&nbsp;&nbsp;";
echo "<input type=\"submit\" value=\"Reset\" name=rst>";
echo "&nbsp;&nbsp;&nbsp;<b>OR</b>&nbsp;&nbsp;&nbsp;";
echo "Show lines from <input type=\"text\" name=lo value=$lo_val 
size=10>&nbsp;&nbsp;&nbsp;";
echo "to&nbsp;&nbsp;&nbsp;<input type=\"text\" name=hi value=$hi_val 
size=10>&nbsp;&nbsp;&nbsp;";
echo "<input type=\"submit\" value=\"Show\" name=go ><br>";

$get_query="select name from filenames";
$p3=mysql_query($get_query);

echo "&nbsp;&nbsp;Load file:&nbsp;&nbsp;";
echo "<select name=files>";
$nofiles=mysql_num_rows($p3);
echo $nofiles;
for ($ii=0; $ii<$nofiles; $ii++)
    {
     $r=mysql_fetch_array($p3);
     echo "<option".(($r["name"]==$files)?' selected':'').">";
     echo ($r["name"]);
     echo "</option>";
    }
echo "</select>";
echo "&nbsp;";
echo "<input type=\"submit\" name=load value=\"Load\">";
echo "<input type=\"hidden\" name=fn value=$filename>";

echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Search for a string&nbsp;";
echo "<input type=\"text\" name=search size=26 value=$vsearch>&nbsp;&nbsp;";
echo "<input type=\"submit\" name=bsearch value=\"Search!\">";

if (!($reverse || $fn)) $reverse=TRUE;
echo "&nbsp;reverse order:&nbsp;<input type='checkbox' name='reverse'".(($reverse)?' 
checked':'').">";
$sortOrder=($reverse)?'ORDER BY date DESC':'';

if ($esearch!=NULL)
                {
                $query="select * from syslog where message like '%$vsearch%' 
$sortOrder limit $lo_val, $hi_val";
                }
        else
                {
                $query="select * from syslog $sortOrder limit $lo_val,$hi_val";
                }
echo "<br>";
echo "<input type=\"hidden\" name=esearch value=$esearch>";
echo "<input type=\"hidden\" name=vsearch value=$vsearch>";
echo "</form>";

$result=mysql_query($query);

$n=$hi_val-$lo_val;

if ($n==0)
         {htmlerror();exit;};
echo "&nbsp;&nbsp;Stats generated for&nbsp;<b>";
echo $hostname;
echo "</b>&nbsp;on&nbsp;<b>";
echo date("F d, Y");
$time_end = getmicrotime();
$time = $time_end - $time_start;

echo "</b>,&nbsp;in <b>$time</b>&nbsp;seconds. (total rows available: $maximum)";

mysql_data_seek($result,0);
echo "<body bgcolor=\"F2EAEA\">";
echo "<table border=0 align=left cellspacing=1 cellpadding=5>";

for ($i=0; $i<$n; $i++)
        {
        $row=mysql_fetch_array($result);
        if (($i%2)==0)
                    {
                     echo "<tr align=\"left\"><td align=center bgcolor=\"C0C0C0\" 
width=13%>";
                    }
                else
                    {
                     echo "<tr align=\"left\"><td align=center bgcolor=\"9db3cc\" 
width=13%>";
                    };
        echo ($row["date"]);
        echo "</td>";
        if (($i%2)==0)
                    {
                     echo "<td align=\"left\"><td align=left bgcolor=\"C0C0C0\" 
width=88%>";
                    }
                else
                    {
                     echo "<td align=\"left\"><td align=left bgcolor=\"9db3cc\" 
width=88%>";
                    };
        echo ($row["message"]);
        echo "</td></tr>";
        }
echo "<tr border=0 cellspacing=0 align=\"left\">";
echo "<td bgcolor=\"F2EAEA\" colspan=3>";


echo "</form>";

echo "<form action=\"index.php\" method=\"POST\"><font size=3>";
echo "&nbsp;<input type=\"submit\" value=\"Logout\" name=exit>";echo "</table>";
echo "</form>";


$clear=unlink("/tmp/mesaje");

?>


Thanks

~Steve

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to