Retrieving MySQL server's port value with PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mitesh

    #1

    Retrieving MySQL server's port value with PHP

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

  • Jerry Stuckle

    #2
    Re: Retrieving MySQL server's port value with PHP

    Mitesh wrote:
    How can I programatticall y 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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Mitesh

      #3
      Re: Retrieving MySQL server's port value with PHP


      Jerry Stuckle wrote:
      Mitesh wrote:
      How can I programatticall y 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.

      Comment

      • Jerry Stuckle

        #4
        Re: Retrieving MySQL server's port value with PHP

        Mitesh wrote:
        Jerry Stuckle wrote:
        >Mitesh wrote:
        >>How can I programatticall y 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.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Gordon Burditt

          #5
          Re: Retrieving MySQL server's port value with PHP

          >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.

          Comment

          • Mitesh

            #6
            Re: Retrieving MySQL server's port value with PHP

            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.

            Comment

            • Jerry Stuckle

              #7
              Re: Retrieving MySQL server's port value with PHP

              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.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              Working...