Location: PHPKode > scripts > sLog > sLog-0.8/db/slogtest.php
<?php
/** sLog v0.8
 *  copyright (c) 2008 Kjell-Inge Gustafsson kigkonsult
 *  www.kigkonsult.se/slog/index.php
 *  hide@address.com
 *
 *  Description:
 *  This file is a PHP HTTP sLog database test interface
 *
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the  Free
 *  Software Foundation; either version 2 of the License, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 *  more details.
 *
 *  You should have received a copy of the GNU General Public License along with
 *  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 *  Place, Suite 330, Boston, MA  02111-1307  USA
 */
require_once '../include/form.php';
fixInput($_REQUEST );
$formParams = array();
// $o = null; foreach($_REQUEST as $k=>$v) $o.=" $k=>$v";echo "$o<br />\n";// test ###
if( isset( $_REQUEST['submit'] ) && ( 0 < $_REQUEST['count'] )) {
  $formParams['message'] = null;
            /* EXECUTE TEST */
  $time_start = getmicrotime();
            /** required : database connection parameters *****/
  $dbserver = 'localhost';
  $database = 'slog';
  $dbuserid = 'slogcaller';
  $dbpasswd = 'slogcaller';
            /** create a database connection ******************/
  $link     = mysql_connect( $dbserver, $dbuserid, $dbpasswd ) or 
              $formParams['message'] = 'Could not connect to db server (mysql errno '.mysql_errno().':'.mysql_error().')';
  if( empty( $formParams['message'] )) {
    mysql_select_db( $database, $link ) or 
              $formParams['message'] = 'Could not select database (mysql errno '.mysql_errno().':'.mysql_error().')';
  }
  if( empty( $formParams['message'] )) {
            /** execute test iterations ***********************/
    for($cnt = 0; $cnt < $_REQUEST['count']; $cnt++ ) {
      $params = fixLogparams( $cnt, $_REQUEST );
            /** create the sql-string *************************/
      $sql    = "SELECT $database.fslog(";
      $sql   .=  "'".$params['date']           .  "'";
      $sql   .= ",'".$params['time']           .  "'";
      $sql   .= ",'".$params['application']    .  "'";
      $sql   .= ",'".$params['service']        .  "'";
      $sql   .= ",'".$params['operation']      .  "'";
      $sql   .= ",'".$params['objno']          .  "'";
      $sql   .= ",'".$params['client']         .  "'";
      $sql   .= ",'".$params['client_spec']    .  "'";
      $sql   .= ",'".$params['organisation']   .  "'";
      $sql   .= ",'".$params['organisation_spec']."'";
      $sql   .= ",'".$params['user1']          .  "'";
      $sql   .= ",'".$params['user2']          .  "'";
      $sql   .= ",'".$params['subject'].' db'  .  "'";
      $sql   .= ",'".$params['body']           .  "'";
      $sql   .= ")";
            /** execute insert ********************************/
      $result    = mysql_query( $sql, $link ) or
           $formParams['message'] = 'execution failed in database, sql:'.wordwrap( $sql, 50, "<br />\n", TRUE)."<br />\n".'(mysql errno '.mysql_errno().':'.mysql_error().')';
      if( !empty( $formParams['message'] )) {
        $_REQUEST['count'] = $cnt + 1;
        break;
      }
            /** checking result and exit **********************/
      if(( $row = mysql_fetch_array( $result, MYSQL_NUM )) && ( '0' != $row[0] )) {
        $formParams['message'] = 'sql: '.wordwrap( $sql, 50, "<br />\n", TRUE)."<br />\nresult:<br />\n".$row[0];
        $_REQUEST['count'] = $cnt + 1;
        break;
      }
    }
  }
  $time_end = getmicrotime();
  $time     = $time_end - $time_start;
  $formParams['avgTime'] = ( empty( $formParams['message'] ) && 1 < $_REQUEST['count'] ) ? ' (avg='.number_format(( $time / $_REQUEST['count'] ), 4 ).')' : '';
  $formParams['time']    = number_format( $time, 4 );
}
$formParams['action'] = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$formParams['title']  = 'sLog simple database test';
$formParams['header'] = 'sLog direct database access test';
$formParams['text']   = 'Test the capacity of sLog direct database access, fill in the number of test log events, update log item counts and START TEST.';
form( $_REQUEST, $formParams );
?>
Return current item: sLog