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


Groups > comp.lang.php > #8972 > unrolled thread

Connecting to MySQL server....

Started bynag <visitnag@gmail.com>
First post2013-04-06 20:23 -0700
Last post2013-04-07 22:13 -0400
Articles 11 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  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

#8972 — Connecting to MySQL server....

Fromnag <visitnag@gmail.com>
Date2013-04-06 20:23 -0700
SubjectConnecting to MySQL server....
Message-ID<ddfedcf5-8332-4072-9f6d-43ac47a5a187@googlegroups.com>
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.

 Thank you.



[toc] | [next] | [standalone]


#8973

From"J.O. Aho" <user@example.net>
Date2013-04-07 09:06 +0200
Message-ID<asck88Fc3U1@mid.individual.net>
In reply to#8972
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

[toc] | [prev] | [next] | [standalone]


#8974

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-04-07 09:07 +0100
Message-ID<kjr9ga$7fe$1@news.albasani.net>
In reply to#8972
On 07/04/13 04: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.
>
>   Thank you.
>
>
>
>
FFS its the first example in the manual
http://php.net/manual/en/function.mysql-select-db.php


<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
     die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
     die ('Can\'t use foo : ' . mysql_error());
}
?>


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#8975

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-04-07 10:45 +0200
Message-ID<ascq0fF180nU1@mid.uni-berlin.de>
In reply to#8972
Am 07.04.2013 05:23, schrieb nag:
> 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.
> 
>  Thank you.
> 
> 
> 
> 
Two more observations:

- you are using the deprecated mysql API, use mysqli or PDO instead.
- if the db server is local, it is a lot faster to connect to a path pointing to a
local socket

/Str.

[toc] | [prev] | [next] | [standalone]


#8977

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-04-07 08:32 -0400
Message-ID<kjror9$npa$1@dont-email.me>
In reply to#8975
On 4/7/2013 4:45 AM, M. Strobel wrote:
> Am 07.04.2013 05:23, schrieb nag:
>> 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.
>>
>>   Thank you.
>>
>>
>>
>>
> Two more observations:
>
> - you are using the deprecated mysql API, use mysqli or PDO instead.
> - if the db server is local, it is a lot faster to connect to a path pointing to a
> local socket
>
> /Str.
>

"localhost" DOES use a socket (Linux) or named pipe (Windows).

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8981

From"M. Strobel" <sorry_no_mail_here@nowhere.dee>
Date2013-04-07 15:09 +0200
Message-ID<asd9fnF4lg7U1@mid.uni-berlin.de>
In reply to#8977
Am 07.04.2013 14:32, schrieb Jerry Stuckle:
> On 4/7/2013 4:45 AM, M. Strobel wrote:
>> Am 07.04.2013 05:23, schrieb nag:
>>> 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.
>>>
>>>   Thank you.
>>>
>>>
>>>
>>>
>> Two more observations:
>>
>> - you are using the deprecated mysql API, use mysqli or PDO instead.
>> - if the db server is local, it is a lot faster to connect to a path pointing to a
>> local socket
>>
>> /Str.
>>
> 
> "localhost" DOES use a socket (Linux) or named pipe (Windows).

I am talking about the difference between AF_UNIX and AF_INET, on Linux - is this new
that "localhost" does not start an IP connection? Can't check now, don't have a test DB.

/Str.

[toc] | [prev] | [next] | [standalone]


#8991

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2013-04-07 16:04 +0100
Message-ID<kjs1ub$pa5$1@news.albasani.net>
In reply to#8981
On 07/04/13 14:09, M. Strobel wrote:
> Am 07.04.2013 14:32, schrieb Jerry Stuckle:
>> On 4/7/2013 4:45 AM, M. Strobel wrote:
>>> Am 07.04.2013 05:23, schrieb nag:
>>>> 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.
>>>>
>>>>    Thank you.
>>>>
>>>>
>>>>
>>>>
>>> Two more observations:
>>>
>>> - you are using the deprecated mysql API, use mysqli or PDO instead.
>>> - if the db server is local, it is a lot faster to connect to a path pointing to a
>>> local socket
>>>
>>> /Str.
>>>
>>
>> "localhost" DOES use a socket (Linux) or named pipe (Windows).
>
> I am talking about the difference between AF_UNIX and AF_INET, on Linux - is this new
> that "localhost" does not start an IP connection? Can't check now, don't have a test DB.
>

last time I checked it was in fact wrong*: localhost seeems to use 
127.0.0.1 not a unix pipe

I know this because whilst I could use the mysql client on a particular 
database, php didn't work with it until I granted IP access on interface 
127.0.0.1 as well.

*But its Jerry, so this is 'normal behaviour'


> /Str.
>


-- 
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to 
lead are elected by the least capable of producing, and where the 
members of society least likely to sustain themselves or succeed, are 
rewarded with goods and services paid for by the confiscated wealth of a 
diminishing number of producers.

[toc] | [prev] | [next] | [standalone]


#9006

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-04-07 22:14 -0400
Message-ID<kjt913$13j$2@dont-email.me>
In reply to#8991
On 4/7/2013 11:04 AM, The Natural Philosopher wrote:
> On 07/04/13 14:09, M. Strobel wrote:
>> Am 07.04.2013 14:32, schrieb Jerry Stuckle:
>>> On 4/7/2013 4:45 AM, M. Strobel wrote:
>>>> Am 07.04.2013 05:23, schrieb nag:
>>>>> 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.
>>>>>
>>>>>    Thank you.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Two more observations:
>>>>
>>>> - you are using the deprecated mysql API, use mysqli or PDO instead.
>>>> - if the db server is local, it is a lot faster to connect to a path
>>>> pointing to a
>>>> local socket
>>>>
>>>> /Str.
>>>>
>>>
>>> "localhost" DOES use a socket (Linux) or named pipe (Windows).
>>
>> I am talking about the difference between AF_UNIX and AF_INET, on
>> Linux - is this new
>> that "localhost" does not start an IP connection? Can't check now,
>> don't have a test DB.
>>
>
> last time I checked it was in fact wrong*: localhost seeems to use
> 127.0.0.1 not a unix pipe
>
> I know this because whilst I could use the mysql client on a particular
> database, php didn't work with it until I granted IP access on interface
> 127.0.0.1 as well.
>
> *But its Jerry, so this is 'normal behaviour'
>
>
>> /Str.
>>
>
>

Then you had something screwed up in your installation.  But then that's 
nothing new.  You ALWAYS have something screwed up.

You were probably trying to connect to Oracle instead of MySQL, and 
don't know the difference.


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#8999

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-04-07 14:17 -0400
Message-ID<kjsd2p$g29$1@dont-email.me>
In reply to#8981
On 4/7/2013 9:09 AM, M. Strobel wrote:
> Am 07.04.2013 14:32, schrieb Jerry Stuckle:
>> On 4/7/2013 4:45 AM, M. Strobel wrote:
>>> Am 07.04.2013 05:23, schrieb nag:
>>>> 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.
>>>>
>>>>    Thank you.
>>>>
>>>>
>>>>
>>>>
>>> Two more observations:
>>>
>>> - you are using the deprecated mysql API, use mysqli or PDO instead.
>>> - if the db server is local, it is a lot faster to connect to a path pointing to a
>>> local socket
>>>
>>> /Str.
>>>
>>
>> "localhost" DOES use a socket (Linux) or named pipe (Windows).
>
> I am talking about the difference between AF_UNIX and AF_INET, on Linux - is this new
> that "localhost" does not start an IP connection? Can't check now, don't have a test DB.
>
> /Str.
>

No, localhost has NEVER started an IP connection in MySQL.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#9004

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2013-04-07 20:08 -0500
Message-ID<slrnkm4653.m9f.hellsop@nibelheim.ninehells.com>
In reply to#8999
On Sun, 07 Apr 2013 14:17:21 -0400, Jerry Stuckle wrote:
> On 4/7/2013 9:09 AM, M. Strobel wrote:
>> Am 07.04.2013 14:32, schrieb Jerry Stuckle:
>>>
>>> "localhost" DOES use a socket (Linux) or named pipe (Windows).
>>
>> I am talking about the difference between AF_UNIX and AF_INET, on Linux - is this new
>> that "localhost" does not start an IP connection? Can't check now, don't have a test DB.
>>
>> /Str.
>>
>
> No, localhost has NEVER started an IP connection in MySQL.

Remember, just to keep things COMPLETELY CONFUSING, that attempting to
connect to "localhost" is a socket or pipe, while attmepting to connect
to "LOCALHOST", "Localhost" or "LoCaLhOsT" goes for IP connections.

-- 
Progress (n.): The process through which Usenet has evolved from
smart people in front of dumb terminals to dumb people in front
of smart terminals.
              -- obs@burnout.demon.co.uk

[toc] | [prev] | [next] | [standalone]


#9005

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-04-07 22:13 -0400
Message-ID<kjt8v7$13j$1@dont-email.me>
In reply to#9004
On 4/7/2013 9:08 PM, Peter H. Coffin wrote:
> On Sun, 07 Apr 2013 14:17:21 -0400, Jerry Stuckle wrote:
>> On 4/7/2013 9:09 AM, M. Strobel wrote:
>>> Am 07.04.2013 14:32, schrieb Jerry Stuckle:
>>>>
>>>> "localhost" DOES use a socket (Linux) or named pipe (Windows).
>>>
>>> I am talking about the difference between AF_UNIX and AF_INET, on Linux - is this new
>>> that "localhost" does not start an IP connection? Can't check now, don't have a test DB.
>>>
>>> /Str.
>>>
>>
>> No, localhost has NEVER started an IP connection in MySQL.
>
> Remember, just to keep things COMPLETELY CONFUSING, that attempting to
> connect to "localhost" is a socket or pipe, while attmepting to connect
> to "LOCALHOST", "Localhost" or "LoCaLhOsT" goes for IP connections.
>

Quite true.  Anything to make it simple, right? :)

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web