FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Connecting to MySQL server....
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Connecting to MySQL server.... [message #181032 is a reply to message #181031] Sun, 07 April 2013 07:06 Go to previous messageGo to previous message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma:
Senior Member
On 07/04/13 05:23, nag wrote:
> Hi,
>
> I have debconnect.php like the following...
>
>
> <?php
>
> $con=mysql_connect("localhost","root","") ;
>
> if(!$con){
> die('Error in Connection: '. mysql_error());
> }
> mysql_select_db('newdb',$con);
>
> ?>
>
> If I give the password or user name wrong it is flashing the error, but if the database name wrong it is simply displaying a blank php file. How can I change the above to show the error even if the wrong database name is given.

Check the example in the online documentation page.
http://www.php.net/manual/en/function.mysql-select-db.php

It's not the perfect way to do it. I would suggest you used try/catch
and throw an exception, the catch would tell the user that there is some
issues (do not show what went wrong, as that can be used to hack your
site), keep in mind to generate the theme outside the try/catch, this
way all pages will look nice no matter what happens.
Use syslog http://www.php.net/manual/en/function.syslog.php
to log what went wrong, now you have somewhere to find all the errors
and without displaying it to the whole world.

--

//Aho
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: comparing arrays
Next Topic: PHP with MS SQL SERVER: is it suitable?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 06:41:33 GMT 2024

Total time taken to generate the page: 0.03948 seconds