By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

mysql_connect()

P: 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
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Andrew Clark wrote:
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!


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

--
Oli

Jul 17 '05 #2

P: n/a
Andrew Clark <no****@nospam.com> wrote:
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:


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.

Jul 17 '05 #3

P: n/a
Daniel Tryba <pa**********@invalid.tryba.nl> wrote in
news:42***********************@news6.xs4all.nl:

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.


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
Jul 17 '05 #4

P: n/a
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
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.