954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Fatal error: Call to undefined function write_log()

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 ("Can't open file " . $this->sql_file_name . "


");
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 ("Line $linenumber: $dumpline


");
}

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 '' . $query . '
';
}

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

if (! mysql_query($query))
{
echo '';
echo 'Error at the line ' . $linenumber . ': ' . trim($dumpline) . '


';
echo 'Query: ' . trim(nl2br(htmlentities($query))) . '


';
echo 'MySQL: ' . mysql_error() . '


';
echo '';
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.

jhowel03
Light Poster
36 posts since Mar 2010
Reputation Points: 10
Solved Threads: 1
 

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.

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 

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

jhowel03
Light Poster
36 posts since Mar 2010
Reputation Points: 10
Solved Threads: 1
 

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.

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You