At 5:22 AM +0200 4/20/01, Marcus Rasmussen wrote:
>I CAN detect if an erro occours. (just some error I did)
>
>I still don't get any return from mysql_errno() or mysql_error()
>I don't iether get a return from mysql_errno() or mysql_error() when
>I do not surpress with @ (the function, mysql_connect(), then prints
>a message.)
>
>Guess I could surpress and write the error message myself, but I
>just want the original one, wich I should be able to get with
>mysql_error()
>
>PS. It is only mysql_connect that do it.
I think this used to be in the docs or notes, but I couldn't find it
when I did a quick search.
As I understand it, mysql_error() and mysql_errno() only return
errors on an active connection. So, if the error occurs on
mysql_connect/pconnect(), they will not return anything. So, you can
do something like:
$LinkId = @mysql_connect(...);
if (!$LinkId) {
call error_function('Unable to connect to database;);
exit;
}
or, more simply:
$LinkId = @mysql_connect(...) or die('Unable to connect to database');
There's no way that I know of to get more details on WHY the connect
failed other than not using the '@' and seeing what the mysql_connect
error message does. In PHP4, you might be able to catch that message
using the output buffering functions, then format that the way you
want. See
http://www.php.net/manual/en/ref.outcontrol.php
for more info on output buffering.
-steve
>Marcus R.
>
>*********** REPLY SEPARATOR ***********
>
>On 20-04-01 at 12:35 David Robley wrote:
>
>>On Fri, 20 Apr 2001 12:19, Marcus Rasmussen wrote:
>>> Hello.
>>>
>>> My question is:
>>> How do I detect if mysql_connect() failed when I'm surpressing the
>>> error message with @ like $linkid =
>>> @mysql_connect("host","user","pass");
>>> And how do I, if it failes, get the error message?
>>>
>>> The manuel says that it:
>>> [quote]Returns a positive MySQL link identifier on success, or an error
>>> message on failure.[unquote]
>>>
>>> In my mind I should be able to detect if it returns an errormessage
>>> like this: if(!$linkid)
>>> $error = mysql_error();
>>> or:
>>> if(!is_int($linkid))
>>> $error = mysql_error();
>>> Noone of theese 2 types works :-(.
>>> I'm using is_int() because the manuel says that mysql_connect() returns
>>> an int. (How can it then return an error message? I thought that an
>>> error message would be some kind if string :-).)
>>>
>>> Here comes another problem, when an error occours I should be able to
>>> see the message with mysql_error() (since the linkid not contains an
>>> error message.)
>>>
>>> Marcus R.
>>
>>Try testing the value of mysql_errno() and echo mysql_error accordingly.
>>
>>--
>>David Robley | WEBMASTER & Mail List Admin
>>RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
>>AusEinet | http://auseinet.flinders.edu.au/
> > Flinders University, ADELAIDE, SOUTH AUSTRALIA
>>
--
+---------- KDVS 90.3fm Annual Fundraiser : 16 - 22 April 2001 ----------+
| Steve Edberg University of California, Davis |
| [EMAIL PROTECTED] Computer Consultant |
| http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |
+----------------------------- www.kdvs.org -----------------------------+
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]