Alright, this is indepth PHP stuff, and it's mostly aimed at Raul. I need to figure this stuff out.<br /><br />Here is a snippet of code from my website's common file:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function db_connect()<br />{<br /> global $VARS;<br /><br /> $Link = mysql_connect($VARS["DB_Host"], $VARS["DB_User"], $VARS["DB_Password"]);<br /> mysql_select_db($VARS["DB_Name"]);<br /><br /> return $Link;<br />}<br /><br />//----------------------------------------------------------<br /><br />function db_query($Query)<br />{<br /> return(mysql_query($Query));<br />}<br /><br />//----------------------------------------------------------<br /><br />function db_row($Result)<br />{<br /> return(mysql_fetch_row($Result));<br />}<br /><br />//----------------------------------------------------------<br /><br />function db_num_rows($Result)<br />{<br /> return(mysql_num_rows($Result));<br />}<!--c2--></div><!--ec2--><br /><br />As you can see, I have setup database functions in my website's common file to handle everything. I've done it this way just in case I ever need to migrate to a new database system rather than MySQL... Anyway...<br /><br />I've got my pages all calling the db_row() etc. functions to interact with my database. Well, my problem is that when there's an error related to MySQL, the error always says it's in my common file... Like so:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->[Tue Feb ? 23:33:06 2004] [error] PHP Warning: é–墆sql_fetch_row(): supplied argument is not a valid MySQL result resource in /blah/blah/blah/commonfile.php on line xxx<!--c2--></div><!--ec2--><br /><br />As you can see from this example, I cannot determine exactly what page has the MySQL error: Because the query is actually executed every time by my common file.<br /><br />Is there a way to have PHP, when outputting MySQL errors, to also include the executing script? Also known as:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$_SERVER["PHP_SELF"]<!--c2--></div><!--ec2--><br /><br />Any possibility? Thanks for help.<!--content-->
Robert, $_SERVER['PHP_SELF'] should work for what you want.<br />Try this:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function db_row($Result)<br />{<br />  $me = $_SERVER['PHP_SELF'];<br />  $row = mysql_fetch_row($Result) or die("Error getting row in '$me': ".mysql_error());<br />  return $row;<br />}<!--c2--></div><!--ec2-->$_SERVER['PHP_SELF'] will refer to the "primary" file being executed, even if the currently executing code is inside a function that resides in another file.<br /><br />As a reference, I tried this to be sure:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/*  test1.php  */<br /><?php<br />  echo "this is the first test file: ".$_SERVER['PHP_SELF']."<br />";<br />  require_once("test2.php");<br />  speak();<br />?><br /><br /><br />-----------------------------<br /><br /><br />/*  test2.php  */<br /><?php<br />  function speak()<br />  {<br />    echo "this is the second test file: ".$_SERVER['PHP_SELF'];<br />  }<br />?><!--c2--></div><!--ec2--><br /><br />And when I pointed my browser to test1.php, the output was <!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->this is the first test file: /test1.php<br />this is the second test file: /test1.php<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Hope this helps <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
K, I'll take a look into that, thanks..<br /><br />Well, the problem here is that the error doesn't stop my pages fom executing. I don't know what page the error is at on my website, because it appears on the Error Log under CPanel.<br /><br />I don't want it to die(), but I want it to put the name of the PHP_SELF file in the Error message that gets put in the Error Log...<!--content-->
Humm... I don't know how it works (never used it) but perhaps PHP's error_log() function is what you need.<br /><br />I suggested the die() function because I thought you didn't want that error. With the die() function, you could see where it is coming from and correct the problem but if you only need to log it, try the error_log() function.<br /><br />By the way, what exactly gets written on the error log? That warning shouldn't be written anywhere, I think... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /><!--content-->
Just gave it a try and it's quite simple. Try something like this:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function db_row($Result)<br />{<br /> Â $me = $_SERVER['PHP_SELF'];<br /> Â $row = mysql_fetch_row($Result) or error_log("Error getting row in '$me': ".mysql_error(), 0);<br /> Â return $row;<br />}<!--c2--></div><!--ec2--> The error message goes into Apache's error log by default <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Thanks Raul, I didn't know about the error_log() function.<br /><br />So far so good, I can't seem to find the problem myeslf. I'm sure whenever it happens I'll be able to find it. Thanks!<!--content-->
Robert, $_SERVER['PHP_SELF'] should work for what you want.<br />Try this:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function db_row($Result)<br />{<br />  $me = $_SERVER['PHP_SELF'];<br />  $row = mysql_fetch_row($Result) or die("Error getting row in '$me': ".mysql_error());<br />  return $row;<br />}<!--c2--></div><!--ec2-->$_SERVER['PHP_SELF'] will refer to the "primary" file being executed, even if the currently executing code is inside a function that resides in another file.<br /><br />As a reference, I tried this to be sure:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->/*  test1.php  */<br /><?php<br />  echo "this is the first test file: ".$_SERVER['PHP_SELF']."<br />";<br />  require_once("test2.php");<br />  speak();<br />?><br /><br /><br />-----------------------------<br /><br /><br />/*  test2.php  */<br /><?php<br />  function speak()<br />  {<br />    echo "this is the second test file: ".$_SERVER['PHP_SELF'];<br />  }<br />?><!--c2--></div><!--ec2--><br /><br />And when I pointed my browser to test1.php, the output was <!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->this is the first test file: /test1.php<br />this is the second test file: /test1.php<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Hope this helps <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
K, I'll take a look into that, thanks..<br /><br />Well, the problem here is that the error doesn't stop my pages fom executing. I don't know what page the error is at on my website, because it appears on the Error Log under CPanel.<br /><br />I don't want it to die(), but I want it to put the name of the PHP_SELF file in the Error message that gets put in the Error Log...<!--content-->
Humm... I don't know how it works (never used it) but perhaps PHP's error_log() function is what you need.<br /><br />I suggested the die() function because I thought you didn't want that error. With the die() function, you could see where it is coming from and correct the problem but if you only need to log it, try the error_log() function.<br /><br />By the way, what exactly gets written on the error log? That warning shouldn't be written anywhere, I think... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /><!--content-->
Just gave it a try and it's quite simple. Try something like this:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function db_row($Result)<br />{<br /> Â $me = $_SERVER['PHP_SELF'];<br /> Â $row = mysql_fetch_row($Result) or error_log("Error getting row in '$me': ".mysql_error(), 0);<br /> Â return $row;<br />}<!--c2--></div><!--ec2--> The error message goes into Apache's error log by default <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Thanks Raul, I didn't know about the error_log() function.<br /><br />So far so good, I can't seem to find the problem myeslf. I'm sure whenever it happens I'll be able to find it. Thanks!<!--content-->