I am on Ubuntu 10.04 using PHP5 and MySQL 5.
Being my first php program I put some tracing code in using fopen, fwrite and fclose to trace what was going on as shown below.
Before I added the handledbrequest function the tracing worked fine and produced trace information in file dumpfile.txt, but after there was no dumpfile.txt generated. After some hours I pinpointed the problem to variable reqnames misssing $ in function handledbrequest. Putting $reqnames cleared the problem and dumpfile.txt reappeared.
My guess is that the php parser stopped when detecting the error which meant the rest of the code was never executed including the fopen, fwrite. Is that so?
Q1. How do I get parsing errors like this to show? (and other errors too)
Q2. If error reporting is controlled by an ini or config file where is it
(for Ubuntu) and what do I put in it?
Would be grateful for advice.
<?php
function handledbrequest ( $con , $reqtp , $sql )
{
$reqnames = array('i'=>'Insert', 'q'=>'Select','u'=>'Update',
'd'=>'Delete');
// skipped section
$error = regnames[$reqtp] . ' error: ' . mysql_error(); //<<<problem
return $error ;
}
$host='localhost';
$userid='root';
$passwd='secret';
$dbname='mydb';
$err= "0";
$myFile = "dumpfile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$con = mysql_connect($host,$userid,$passwd);
fwrite($fh, "con=$con\
");
if (!$con)
{
$err = 'Could not connect: ' . mysql_error();
}
else
{
$dbselected = mysql_select_db($dbname, $con);
if ( !$dbselected )
{
$err = 'Could not select db: '. $dbname . ' '. mysql_error();
}
else
{
fwrite($fh, "$dbname dbselected\
");
$reqtp = $_GET['req'];
$sql = $_GET['sql'];
fwrite($fh, "req=$reqtp sql=$sql\
");
//$err = handledbrequest ( $con , $reqtp, $sql );
}
fwrite($fh, "err=$err\
");
}
fclose($fh);
?>