0

Fatal error: Call to undefined function write_log() in /home/poetryba/public_html/install/inc/class.sql_import.php on line 105

here is my code

<?php

class Sql2Db
{
    private $sql_file_name = '';
    private $debug = '';
    public $debug_filename = 'vshare_upgrade';

    function Sql2Db($sql_file_name, $debug = 0)
    {
        $this->sql_file_name = $sql_file_name;
        $this->debug = $debug;
    }

    function import()
    {

        $comment = array();
        $comment[] = '#';
        $comment[] = '-- ';

        $query = '';
        $queries = 0;
        $querylines = 0;
        $inparents = false;
        $linenumber = 1;
        $totalqueries = 0;

        if (! $file = @fopen($this->sql_file_name, 'rt'))
        {
            echo ("<p>Can't open file " . $this->sql_file_name . "</p>");
            exit();
        }

        $end_of_file = 1;

        while ($end_of_file)
        {

            $dumpline = '';

            while (! feof($file) && substr($dumpline, - 1) != "\n")
            {
                $dumpline .= fgets($file, 16384);
            }

            if ($dumpline === '')
            {
                break;
            }

            $dumpline = str_replace("\r\n", "\n", $dumpline);
            $dumpline = str_replace("\r", "\n", $dumpline);

            if ($this->debug)
            {
                echo ("<p>Line $linenumber: $dumpline</p>");
            }

            if (! $inparents)
            {
                $skipline = false;

                foreach ($comment as $comment_value)
                {
                    if (! $inparents && (trim($dumpline) == '' || strpos($dumpline, $comment_value) === 0))
                    {
                        $skipline = true;
                        break;
                    }
                }

                if ($skipline)
                {
                    $linenumber ++;
                    continue;
                }
            }

            $dumpline_deslashed = str_replace("\\\\", "", $dumpline);

            $parents = substr_count($dumpline_deslashed, "'") - substr_count($dumpline_deslashed, "\\'");

            if ($parents % 2 != 0)
            {
                $inparents = ! $inparents;
            }

            $query .= $dumpline;

            if (! $inparents)
            {
                $querylines ++;
            }

            if (ereg(";$", trim($dumpline)) && ! $inparents)
            {
                $query = trim($query);

                if ($this->debug)
                {
                    echo '<textarea cols="100">' . $query . '</textarea><br />';
                }

                write_log($query, $this->debug_filename, 0, 'txt');

                if (! mysql_query($query))
                {
                    echo '<hr />';
                    echo '<p class="error">Error at the line ' . $linenumber . ': ' . trim($dumpline) . '</p>';
                    echo '<p>Query: ' . trim(nl2br(htmlentities($query))) . '</p>';
                    echo '<p>MySQL: ' . mysql_error() . '</p>';
                    echo '<hr />';
                    exit();
                }

                $totalqueries ++;
                $queries ++;
                $query = '';
                $querylines = 0;
            }
            $linenumber ++;
        }
    }
}

someone please help im so tired its been error after error.
im about to pull my hair out.

Edited by Reverend Jim: Fixed formatting

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Will Gresham
0

You do not have a function called 'write_log' within the class in the above script.

If the function 'write_log' is defined outside the class, you cannot reference it as you are trying as it is not registered in the class.

Take a look at this

Also, use code tags.

Edited by Will Gresham: n/a

0

im not sure how to fix this error i kinda understand what your saying. but I have no idea how to fix it.

this is the line of code in question
write_log($query, $this->debug_filename, 0, 'txt');

i thought this was my function

0

That line would look for a function called write_log, and send it the values
$query
$this->debug_filename
0
and 'txt'

write_log is not a PHP function, so you will need to have a custom one defined somewhere with this name.

So, somewhere in your script you will need to have the function telling it what to do, e.g.:

function write_log($used_query, $filename, $status, $type) {
  // Do something with the values here
}

That is just an example, I don't know what the values you are sending are for so the vars I used may not be appropriate.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.