469,645 Members | 1,602 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Retrieving MySQL server's port value with PHP

How can I programattically retrieve MySQL server's port value through
PHP?

Mar 18 '07 #1
6 4006
Mitesh wrote:
How can I programattically retrieve MySQL server's port value through
PHP?
Did you try

ini_get('mysql.default_port');

(or, if you have mysqli installed...)

ini_get('mysqli.default_port');

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 18 '07 #2

Jerry Stuckle wrote:
Mitesh wrote:
How can I programattically retrieve MySQL server's port value through
PHP?

Did you try

ini_get('mysql.default_port');

(or, if you have mysqli installed...)

ini_get('mysqli.default_port');
Thanx Jerry for the reply:

This returns the default port value. But when the MySQL server is
installed the app that runs after the installation lets the user
configure the MySQL port. Now I need to access this port value through
the PHP. My PHP script only works for the port value that is pre-
defined. So when the user again does configuration and changes the
port value, my PHP script (which calls my sql functions) no longer
works.

I think I have no alternative than to open the MySQL ini file through
PHP and search for the "port" text and retrieve it's value.

Mar 18 '07 #3
Mitesh wrote:
Jerry Stuckle wrote:
>Mitesh wrote:
>>How can I programattically retrieve MySQL server's port value through
PHP?
Did you try

ini_get('mysql.default_port');

(or, if you have mysqli installed...)

ini_get('mysqli.default_port');

Thanx Jerry for the reply:

This returns the default port value. But when the MySQL server is
installed the app that runs after the installation lets the user
configure the MySQL port. Now I need to access this port value through
the PHP. My PHP script only works for the port value that is pre-
defined. So when the user again does configuration and changes the
port value, my PHP script (which calls my sql functions) no longer
works.

I think I have no alternative than to open the MySQL ini file through
PHP and search for the "port" text and retrieve it's value.
If you change the port in the MySQL configuration, you should also
change it in your php configuration. That's what they're there for.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 18 '07 #4
>I think I have no alternative than to open the MySQL ini file through
>PHP
Hopefully, you do not have permission necessary to do that.
It's going to be especially difficult if the server is on a different
machine from PHP.

You also don't know which MySQL ini file is actually being used by the
instance of MySQL you want to access.
>and search for the "port" text and retrieve it's value.

Mar 18 '07 #5
Thanx Jerry:

Fine point

Gordon Burditt wrote:
I think I have no alternative than to open the MySQL ini file through
PHP

Hopefully, you do not have permission necessary to do that.
It's going to be especially difficult if the server is on a different
machine from PHP.
Thanx Gordon:

Ah! I didn't supply enough information. Actual the above is not a
problem for me right now. But can be in future version of the app.
Currently the PHP is only accessed by the administrator and the
administrator and the servers (both MySQL and Apache) is on the same
machine.

But in the future spec version 2.0 I do see a requirement that the
administrator should be able to log on into the system from any one
of the LAN machines. So that can be a problem.

I think Jerry's way should solve this problem too. The configuration
exe is run on the machine where the servers are located.

Mar 19 '07 #6
Mitesh wrote:
Thanx Jerry:

Fine point

Gordon Burditt wrote:
>>I think I have no alternative than to open the MySQL ini file through
PHP
Hopefully, you do not have permission necessary to do that.
It's going to be especially difficult if the server is on a different
machine from PHP.

Thanx Gordon:

Ah! I didn't supply enough information. Actual the above is not a
problem for me right now. But can be in future version of the app.
Currently the PHP is only accessed by the administrator and the
administrator and the servers (both MySQL and Apache) is on the same
machine.

But in the future spec version 2.0 I do see a requirement that the
administrator should be able to log on into the system from any one
of the LAN machines. So that can be a problem.

I think Jerry's way should solve this problem too. The configuration
exe is run on the machine where the servers are located.
One word of caution. Other machines are going to expect MySQL to be
using port 3306. Their PHP installations won't be affected by the
change to the original php.ini. So if you're going to be accessing
MySQL from PHP (or any other language, for that matter) on a different
port, you'll have to specify it in the mysql_connect() (or equivalent) call.

I just find it easier to go ahead and leave it on 3306. And if you're
thinking of moving it for security reasons - forget it. It takes about
30 seconds to find every open port on your system - and the script is
only a half dozen lines long. It might take another minute (and 5 lines
of script) to determine which port MySQL is actually using.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 19 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by philippe Tressard | last post: by
reply views Thread by Mike Chirico | last post: by
1 post views Thread by PowerLifter1450 | last post: by
1 post views Thread by polycom | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.