Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8973

Re: Connecting to MySQL server....

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Connecting to MySQL server....
Date 2013-04-07 09:06 +0200
Message-ID <asck88Fc3U1@mid.individual.net> (permalink)
References <ddfedcf5-8332-4072-9f6d-43ac47a5a187@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Connecting to MySQL server.... nag <visitnag@gmail.com> - 2013-04-06 20:23 -0700
  Re: Connecting to MySQL server.... "J.O. Aho" <user@example.net> - 2013-04-07 09:06 +0200
  Re: Connecting to MySQL server.... The Natural Philosopher <tnp@invalid.invalid> - 2013-04-07 09:07 +0100
  Re: Connecting to MySQL server.... "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-04-07 10:45 +0200
    Re: Connecting to MySQL server.... Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-07 08:32 -0400
      Re: Connecting to MySQL server.... "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-04-07 15:09 +0200
        Re: Connecting to MySQL server.... The Natural Philosopher <tnp@invalid.invalid> - 2013-04-07 16:04 +0100
          Re: Connecting to MySQL server.... Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-07 22:14 -0400
        Re: Connecting to MySQL server.... Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-07 14:17 -0400
          Re: Connecting to MySQL server.... "Peter H. Coffin" <hellsop@ninehells.com> - 2013-04-07 20:08 -0500
            Re: Connecting to MySQL server.... Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-07 22:13 -0400

csiph-web