FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Not bale to connect to MySQL with PHP
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Not bale to connect to MySQL with PHP [message #169642 is a reply to message #169641] Mon, 20 September 2010 22:05 Go to previous messageGo to previous message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma:
Member
Denis McMahon wrote:
> On 20/09/10 20:32, MikeB wrote:
>> I have defined (just for testing) a user in my SQL named "pubuser" and
>> granted it access to a database "publications." Of course I also created
>> the database and two tables.
>>
>> I can access and manipulate the tables via phpMyAdmin and I can log in
>> to sql using pubuser via the command-line interface.
>>
>> I have the following php code:
>>
>> <?php // login.php
>> $db_hostname = 'localhost';
>> $db_database = 'publications';
>> $db_username = 'pubuser';
>> $db_password = 'abc';
>> ?>
>>
>>
>> also I have a test web page:
>>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>> <html>
>> <head>
>> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
>> <title>Connect to SQL</title>
>> </head>
>> <body>
>> <?php
>> Echo "Hello";
>> require_once 'login.php';
>> echo "got require";
>> $db_server = mysql_connect($db_hostname, $db_username, $db_password);
>> if (!$db_server)
>> die("Unable to connect to MySQL: " . mysql_error());
>> echo "Congrats, it seems you have connected to the server<br />
>> host: $db_hostname<br />
>> user: $db_username<br />
>> password: $db_password<br />
>> for database: $db_database<br />";
>> print_r($db_server);
>> ?>
>> </body>
>> </html>
>>
>> If I try to run this, it briefly says "connecting to localhost" and then
>> indefinitely it says "waiting for localhost..."
>>
>> If I comment out the connect statement, the rest runs. What should I
>> look for?
>
> Are you doing all of this on a single machine? Or do have a separate
> server and user machine?

I'm learning PHP and MySQL from an O"Reilly book. The book had me
download and install EasyPHP. So yes, everything is on my machine. Up to
now all my PHP-only examples have worked just fine.
>
> localhost to the php process means the web server - so it's looking for
> mysql on the web server, which is not necessarily the machine you're
> running the browser on.

I think in this instance it is.

>
> Are mysql and php in agreement as to which port to use?

In phpinfo(), it says:

mysql.default_port no value no value
mysql.default_socket no value no value

The mysqli section says:
mysqli.default_host no value no value
mysqli.default_port 3306 3306

The [client] section of my.ini has

port = 3306
socket = /tmp/mysql.sock

and
[mysqld]
port=3306
bind-address = 127.0.0.1
socket = /tmp/mysql.sock
>
> What hosts(s) are defined in phpmyadmin for the user?

localhost or 127.0.0.1

>
> can you telnet to the mysql port on the server from a terminal session
> on the server? eg telnet to the server, and then on the server "telnet
> localhost 3306" (or whatever your mysql port is). What happens?

I think this is just for the case where the two are on different
servers, right?

Thanks for your help on this.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Php Include bug in firefox
Next Topic: Feed RSS and accented and other special chars
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 16:50:25 GMT 2024

Total time taken to generate the page: 0.05312 seconds