Connecting Tech Pros Worldwide Help | Site Map

mysql_connect()

  #1  
Old July 17th, 2005, 02:30 PM
Andrew Clark
Guest
 
Posts: n/a
Hello,

I am having trouble connecting to my server with mysql_connect(). I can
connect via the command line on the server and with phpMyAdmin over our
network, but not though mysql_connect(). This is my script:

<?php
$host = '192.168.100.5';
$user = 'root';
$pass = <password>;

echo '<P>Connecting...</P>';
//echo 'mysql_connect('.$host.', '.$user.', '.$pass.');';
//$link = false;
$link = mysql_connect($host, $user, $pass) or die(mysql_error());

if ($link)
{
echo '<P>Connection OK!</P>';
mysql_close($link);
}
else
{
echo '<P>Connection failed.</P>';
}
?>


The last thing I see on the page when I load this is "Connecting..." -
nothing else. It's been a while since I have worked with PHP/MySQL so
please bear with me!

Thanks,
Andrew
  #2  
Old July 17th, 2005, 02:30 PM
Oli Filth
Guest
 
Posts: n/a

re: mysql_connect()


Andrew Clark wrote:[color=blue]
> Hello,
>
> I am having trouble connecting to my server with mysql_connect(). I can
> connect via the command line on the server and with phpMyAdmin over our
> network, but not though mysql_connect(). This is my script:
>
> <?php
> $host = '192.168.100.5';
> $user = 'root';
> $pass = <password>;
>
> echo '<P>Connecting...</P>';
> //echo 'mysql_connect('.$host.', '.$user.', '.$pass.');';
> //$link = false;
> $link = mysql_connect($host, $user, $pass) or die(mysql_error());
>
> if ($link)
> {
> echo '<P>Connection OK!</P>';
> mysql_close($link);
> }
> else
> {
> echo '<P>Connection failed.</P>';
> }
> ?>
>
>
> The last thing I see on the page when I load this is "Connecting..." -
> nothing else. It's been a while since I have worked with PHP/MySQL so
> please bear with me![/color]

Call echo mysql_error(); after every MySQL function call to find out
what the issue is.

--
Oli

  #3  
Old July 17th, 2005, 02:30 PM
Daniel Tryba
Guest
 
Posts: n/a

re: mysql_connect()


Andrew Clark <nospam@nospam.com> wrote:[color=blue]
> I am having trouble connecting to my server with mysql_connect(). I can
> connect via the command line on the server and with phpMyAdmin over our
> network, but not though mysql_connect(). This is my script:[/color]

Both these methods connect to "localhost". Your script suggests remote
access, this will not work since in many cases networking is disabled by
default (Good Thing(tm)). So read the mysql documentation and make sure
it's accepting remote network connections.

  #4  
Old July 17th, 2005, 02:30 PM
Andrew Clark
Guest
 
Posts: n/a

re: mysql_connect()


Daniel Tryba <partmapsswen@invalid.tryba.nl> wrote in
news:42a70940$0$49819$c5fe704e@news6.xs4all.nl:
[color=blue]
>
> Both these methods connect to "localhost". Your script suggests remote
> access, this will not work since in many cases networking is disabled
> by default (Good Thing(tm)). So read the mysql documentation and make
> sure it's accepting remote network connections.
>[/color]

Well, since I am running this on my local machine, I changed it to
locahost anyway. That IP was my machine's IP. But anyway.

After I changed it to localhost it still is not connecting. Nothing is
being output to the page after the call to mysql_connect().

Andrew
  #5  
Old July 17th, 2005, 02:30 PM
Andrew Clark
Guest
 
Posts: n/a

re: mysql_connect()


I got it! Wow, not too smart, I am.

It seems I kind of forgot to enable the MySQL extension in php.ini...

Thanks to all,
Andrew
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to escape mysql_connect() DNS caching? hugo answers 1 August 22nd, 2006 01:45 PM
mysql_connect error Apache Web server to Windows hosted database GD answers 6 July 25th, 2006 12:35 PM
Cannot get mysql_connect to work Michael answers 19 December 29th, 2005 02:35 PM
Help: mysql_connect() doesn't seem to return resource link indentifier. Sugapablo answers 2 December 14th, 2005 08:45 PM
Making mysql_connect more efficient in my script LRW answers 1 July 17th, 2005 04:39 AM