Re: [PHP] How to get error context

2008-03-17 Thread Zoltán Németh

2008. 03. 14, péntek keltezéssel 10.03-kor It Maq ezt írta:
> Here is the error message captured by my error
> handling function:
> 
> mysql_connect() [function.mysql-connect]: Access
> denied for user 'admin'@'localhost' (using password:
> YES)
> 
> i put a wrong password and username

the manual also says this, which I too did not notice earlier:

"Note: You can suppress the error message on failure by prepending a @
to the function name."

this implies that error message is raised on error, but don't ask me
why ;)

greets,
Zoltán Németh

> --- Zoltán Németh <[EMAIL PROTECTED]> wrote:
> 
> > 2008. 03. 14, péntek keltezéssel 07.40-kor It Maq
> > ezt írta:
> > > For example "mysql_connect" reprted automatically
> > the
> > > error but in the manual
> > >
> >
> http://us3.php.net/manual/en/function.mysql-connect.php
> > >  all they give as information is the return:
> > "Returns
> > > a MySQL link identifier on success, or FALSE on
> > > failure.", where can i see if it throws an error,
> > and
> > > when you say throwing do you mean that i can catch
> > the
> > > error without throwing it myself?
> > 
> > hmm actually what error did mysql_connect throw?
> > because if it just fails connecting, it returns
> > false. on the other
> > hand, if you provide it wrong arguments (e.g. less
> > arguments, or wrong
> > data type, or whatever) that raises a php error and
> > the function does
> > not even run.
> > this is true for most functions which return false
> > on error. the
> > returning false means there was some error with the
> > action itself, while
> > php errors are raised when the action can not be
> > executed because of
> > some error in the code itself.
> > 
> > greets,
> > Zoltán Németh
> > 
> > >  
> > > --- Zoltán Németh <[EMAIL PROTECTED]> wrote:
> > > 
> > > > 2008. 03. 14, péntek keltezéssel 07.20-kor It
> > Maq
> > > > ezt írta:
> > > > > So i'm wondering if there are some rules
> > > > > that can help me know if an error will be
> > reported
> > > > > automatically or not. 
> > > > 
> > > > there is no general rule for that. you have to
> > check
> > > > the manual for each
> > > > function, some of them just returns false on
> > error,
> > > > others throw
> > > > warnings/notices/errors...
> > > > 
> > > > greets,
> > > > Zoltán Németh
> > > > 
> > > > 
> > > 
> > > 
> > > 
> > >  
> >
> 
> > > Never miss a thing.  Make Yahoo your home page. 
> > > http://www.yahoo.com/r/hs
> > > 
> > > 
> > 
> > 
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > 
> 
> 
> 
>   
> 
> Looking for last minute shopping deals?  
> Find them fast with Yahoo! Search.  
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to get error context

2008-03-14 Thread It Maq
Here is the error message captured by my error
handling function:

mysql_connect() [function.mysql-connect]: Access
denied for user 'admin'@'localhost' (using password:
YES)

i put a wrong password and username
--- Zoltán Németh <[EMAIL PROTECTED]> wrote:

> 2008. 03. 14, péntek keltezéssel 07.40-kor It Maq
> ezt írta:
> > For example "mysql_connect" reprted automatically
> the
> > error but in the manual
> >
>
http://us3.php.net/manual/en/function.mysql-connect.php
> >  all they give as information is the return:
> "Returns
> > a MySQL link identifier on success, or FALSE on
> > failure.", where can i see if it throws an error,
> and
> > when you say throwing do you mean that i can catch
> the
> > error without throwing it myself?
> 
> hmm actually what error did mysql_connect throw?
> because if it just fails connecting, it returns
> false. on the other
> hand, if you provide it wrong arguments (e.g. less
> arguments, or wrong
> data type, or whatever) that raises a php error and
> the function does
> not even run.
> this is true for most functions which return false
> on error. the
> returning false means there was some error with the
> action itself, while
> php errors are raised when the action can not be
> executed because of
> some error in the code itself.
> 
> greets,
> Zoltán Németh
> 
> >  
> > --- Zoltán Németh <[EMAIL PROTECTED]> wrote:
> > 
> > > 2008. 03. 14, péntek keltezéssel 07.20-kor It
> Maq
> > > ezt írta:
> > > > So i'm wondering if there are some rules
> > > > that can help me know if an error will be
> reported
> > > > automatically or not. 
> > > 
> > > there is no general rule for that. you have to
> check
> > > the manual for each
> > > function, some of them just returns false on
> error,
> > > others throw
> > > warnings/notices/errors...
> > > 
> > > greets,
> > > Zoltán Németh
> > > 
> > > 
> > 
> > 
> > 
> >  
>

> > Never miss a thing.  Make Yahoo your home page. 
> > http://www.yahoo.com/r/hs
> > 
> > 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 



  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to get error context

2008-03-14 Thread Zoltán Németh
2008. 03. 14, péntek keltezéssel 07.40-kor It Maq ezt írta:
> For example "mysql_connect" reprted automatically the
> error but in the manual
> http://us3.php.net/manual/en/function.mysql-connect.php
>  all they give as information is the return: "Returns
> a MySQL link identifier on success, or FALSE on
> failure.", where can i see if it throws an error, and
> when you say throwing do you mean that i can catch the
> error without throwing it myself?

hmm actually what error did mysql_connect throw?
because if it just fails connecting, it returns false. on the other
hand, if you provide it wrong arguments (e.g. less arguments, or wrong
data type, or whatever) that raises a php error and the function does
not even run.
this is true for most functions which return false on error. the
returning false means there was some error with the action itself, while
php errors are raised when the action can not be executed because of
some error in the code itself.

greets,
Zoltán Németh

>  
> --- Zoltán Németh <[EMAIL PROTECTED]> wrote:
> 
> > 2008. 03. 14, péntek keltezéssel 07.20-kor It Maq
> > ezt írta:
> > > So i'm wondering if there are some rules
> > > that can help me know if an error will be reported
> > > automatically or not. 
> > 
> > there is no general rule for that. you have to check
> > the manual for each
> > function, some of them just returns false on error,
> > others throw
> > warnings/notices/errors...
> > 
> > greets,
> > Zoltán Németh
> > 
> > 
> 
> 
> 
>   
> 
> Never miss a thing.  Make Yahoo your home page. 
> http://www.yahoo.com/r/hs
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to get error context

2008-03-14 Thread It Maq
For example "mysql_connect" reprted automatically the
error but in the manual
http://us3.php.net/manual/en/function.mysql-connect.php
 all they give as information is the return: "Returns
a MySQL link identifier on success, or FALSE on
failure.", where can i see if it throws an error, and
when you say throwing do you mean that i can catch the
error without throwing it myself?
 
--- Zoltán Németh <[EMAIL PROTECTED]> wrote:

> 2008. 03. 14, péntek keltezéssel 07.20-kor It Maq
> ezt írta:
> > So i'm wondering if there are some rules
> > that can help me know if an error will be reported
> > automatically or not. 
> 
> there is no general rule for that. you have to check
> the manual for each
> function, some of them just returns false on error,
> others throw
> warnings/notices/errors...
> 
> greets,
> Zoltán Németh
> 
> 



  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to get error context

2008-03-14 Thread Zoltán Németh
2008. 03. 14, péntek keltezéssel 07.20-kor It Maq ezt írta:
> So i'm wondering if there are some rules
> that can help me know if an error will be reported
> automatically or not. 

there is no general rule for that. you have to check the manual for each
function, some of them just returns false on error, others throw
warnings/notices/errors...

greets,
Zoltán Németh


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to get error context

2008-03-14 Thread It Maq
Hi,

I maid the modifications you suggested. For the error
context when i display it, it gives a lot of
information, but not easy to understand how the array
is structured. If somebody knows about a site
explaining how to access the context it would be
great.
I also modified the error reporting to E_ALL as you
suggested. Now an other question arise: For the
connection to the database if i put a wrong username
or password the error is reported automatically to the
function that i defined as the error handling
function, but for the next statement (see code below)
if i put a wrong database name the error is not
reported automatically, i have to trigger it using
triger_error. So i'm wondering if there are some rules
that can help me know if an error will be reported
automatically or not. here is my code after
modification:

";

switch($errno) {
case E_USER_ERROR: $type = 
"E_USER_ERROR";break;
case E_USER_WARNING: $type =
"E_USER_WARNING";break; 
case E_USER_NOTICE: $type = 
"E_USER_NOTICE";break;
case E_ERROR: $type = "E_ERROR";break;
case E_WARNING: $type = "E_WARNING";break;
case E_PARSE: $type = "E_PARSE";break;
case E_NOTICE: $type = "E_NOTICE";break;
case E_CORE_ERROR: $type = "E_CORE_ERROR";break;
case E_CORE_WARNING: $type =
"E_CORE_WARNING";break; 
case E_COMPILE_ERROR: $type =
"E_COMPILE_ERROR";break;
case E_STRICT: $type = "E_STRICT";break;
case E_COMPILE_WARNING: $type =
"E_COMPILE_WARNING";break;  
case E_RECOVERABLE_ERROR: $type =
"E_RECOVERABLE_ERROR";break;
default: echo "This is an error not listed";

}
$str = "";
$str .= "ERROR TYPE: ". $type;
$str .= "ERROR Number: ". $errno;
$str .= "ERROR MESSAGE: ". $errstr;
$str.= "File: ". $filename;
$str.= "Line number: ". $lineno;
echo $str;
echo "Context: ";
print_r($errcontext);
}





echo "Testing set_error_handler";

error_reporting(E_ALL);  
set_error_handler('error_handler'); 
mysql_connect("localhost", "admin", "admin"); 
mysql_select_db("wrongdb") or trigger_error("wrong
database");

?>
--- Jim Lucas <[EMAIL PROTECTED]> wrote:

> It Maq wrote:
> > Hi,
> > 
> > i need help because I'm unable to retrieve error's
> context. Below is the code that is working perfectly
> except the context that is not displayed:
> > 
> >  > function error_handler($errno, $errstr,
> $filename, $lineno, $errcontext)
> > {
> > 
> 
> try doing a print_r($errcontext) here and see what
> you get?
> 
> maybe the zero index does not exist.
> 
> >   
> > $str = "";
> > $str .= "ERROR Number: ". $errno;
> > $str .= "ERROR MESSAGE: ". $errstr;
> > $str.= "File: ". $filename;
> > $str.= "Line number: ". $lineno;
> > $str.= "Context: ". $errcontext[0];
> > echo $str;
> > 
> > 
> > }
> > 
> > echo "Testing set_error_handler";
> > 
> 
> I have always used
> error_reporting(E_ALL);
> instead of this.
> > error_reporting(0);  
> > set_error_handler('error_handler'); 
> > ini_set('error_reporting', 0);
> 
> I have never seen the above line before.  This and
> the error_reporting(0) would 
> probably suppress all error messages generated by
> PHP.  Double check these 
> settings and make sure the you can still trigger an
> error with trigger_error() 
> if you have error_reporting() turned off.
> 
> > 
> > //trigger_error("The string for testing the
> error", E_USER_WARNING);
> > $ourFileName = "testFile.txt";
> > $fh = fopen($ourFileName, 'X');// or die("Can't
> open file");
> > fclose($fh);
> > 
> > 
> > ?>



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to get error context

2008-03-13 Thread Jim Lucas

It Maq wrote:

Hi,

i need help because I'm unable to retrieve error's context. Below is the code 
that is working perfectly except the context that is not displayed:




try doing a print_r($errcontext) here and see what you get?

maybe the zero index does not exist.

  
$str = "";

$str .= "ERROR Number: ". $errno;
$str .= "ERROR MESSAGE: ". $errstr;
$str.= "File: ". $filename;
$str.= "Line number: ". $lineno;
$str.= "Context: ". $errcontext[0];
echo $str;



}

echo "Testing set_error_handler";



I have always used
error_reporting(E_ALL);
instead of this.
error_reporting(0);  
set_error_handler('error_handler'); 
ini_set('error_reporting', 0);


I have never seen the above line before.  This and the error_reporting(0) would 
probably suppress all error messages generated by PHP.  Double check these 
settings and make sure the you can still trigger an error with trigger_error() 
if you have error_reporting() turned off.




//trigger_error("The string for testing the error", E_USER_WARNING);
$ourFileName = "testFile.txt";
$fh = fopen($ourFileName, 'X');// or die("Can't open file");
fclose($fh);


?>




  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 







--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to get error context

2008-03-13 Thread It Maq
Hi,

i need help because I'm unable to retrieve error's context. Below is the code 
that is working perfectly except the context that is not displayed:

ERROR Number: ". $errno;
$str .= "ERROR MESSAGE: ". $errstr;
$str.= "File: ". $filename;
$str.= "Line number: ". $lineno;
$str.= "Context: ". $errcontext[0];
echo $str;


}

echo "Testing set_error_handler";

error_reporting(0);  
set_error_handler('error_handler'); 
ini_set('error_reporting', 0);

//trigger_error("The string for testing the error", E_USER_WARNING);
$ourFileName = "testFile.txt";
$fh = fopen($ourFileName, 'X');// or die("Can't open file");
fclose($fh);


?>




  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php