Connecting to MySQL server.... [message #181031] |
Sun, 07 April 2013 03:23 |
Nagaraju Kachapuram
Messages: 14 Registered: February 2013
Karma: 0
|
Junior Member |
|
|
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.
|
|
|
Re: Connecting to MySQL server.... [message #181032 is a reply to message #181031] |
Sun, 07 April 2013 07:06 |
J.O. Aho
Messages: 194 Registered: September 2010
Karma: 0
|
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
|
|
|
Re: Connecting to MySQL server.... [message #181033 is a reply to message #181031] |
Sun, 07 April 2013 08:07 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Connecting to MySQL server.... [message #181034 is a reply to message #181031] |
Sun, 07 April 2013 08:45 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Connecting to MySQL server.... [message #181036 is a reply to message #181034] |
Sun, 07 April 2013 12:32 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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(at)attglobal(dot)net
==================
|
|
|
Re: Connecting to MySQL server.... [message #181040 is a reply to message #181036] |
Sun, 07 April 2013 13:09 |
M. Strobel
Messages: 386 Registered: December 2011
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Connecting to MySQL server.... [message #181049 is a reply to message #181040] |
Sun, 07 April 2013 15:04 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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.
|
|
|
Re: Connecting to MySQL server.... [message #181057 is a reply to message #181040] |
Sun, 07 April 2013 18:17 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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(at)attglobal(dot)net
==================
|
|
|
Re: Connecting to MySQL server.... [message #181062 is a reply to message #181057] |
Mon, 08 April 2013 01:08 |
Peter H. Coffin
Messages: 245 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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(at)burnout(dot)demon(dot)co(dot)uk
|
|
|
Re: Connecting to MySQL server.... [message #181063 is a reply to message #181062] |
Mon, 08 April 2013 02:13 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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(at)attglobal(dot)net
==================
|
|
|
Re: Connecting to MySQL server.... [message #181064 is a reply to message #181049] |
Mon, 08 April 2013 02:14 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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(at)attglobal(dot)net
==================
|
|
|