connecting to db..

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

    #1

    connecting to db..

    this seems pretty straight-forward.. got this code

    $link = mysql_connect(' localhost:3306' , '<uid>', '<pswd>');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($li nk);

    from here..


    but can't connect, get this error:

    Connect to db:
    Warning: mysql_connect() [function.mysql-connect]: Can't connect to
    MySQL server on 'localhost' (10061) in
    C:\xampp\xampp\ htdocs\home\con n.php on line 19
    Could not connect: Can't connect to MySQL server on 'localhost' (10061)

    I connect to this same MySQL server from Tomcat w/no problem.. what is
    issue here pls...


    now on top of pg mentioned above, there this description:

    resource mysql_connect ( [string server [, string username [, string
    password [, bool new_link [, int client_flags]]]]] )

    what does 'resource' refer to here pls... and where to do specify what
    db to connect to... (in java you put db-name in same line where you
    make the connection..)
    (and don't you need a driver to connect, I use a JDBC driver to
    connect w/Java..)

    would very much appreciate some help.. thank you...

    Frances

  • Frances

    #2
    Re: connecting to db..


    disregard -- now all of a sudden can't connect from Java either.. I
    don't get this.. I've been connecting successfully to db for over a
    year from both Tomcat & java stand-alone classes, now all of a sudden am
    trying to connect also from PHP and I can't connect at all..

    when try to connect just from console get error:

    ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

    what is this.. what is 10061.. :(

    is it really not possible then to connect to one MySQL server from diff
    web servers? (I don't think so..) I want to set up my machine so can
    connect to same MySQL server from Tomcat, IIS, PHP.. (the port thing is
    also a big pain and don't know if will be able to pull this off..) thank
    you very much..

    Frances



    Frances wrote:[color=blue]
    > this seems pretty straight-forward.. got this code
    >
    > $link = mysql_connect(' localhost:3306' , '<uid>', '<pswd>');
    > if (!$link) {
    > die('Could not connect: ' . mysql_error());
    > }
    > echo 'Connected successfully';
    > mysql_close($li nk);
    >
    > from here..
    > http://us2.php.net/function.mysql-connect
    >
    > but can't connect, get this error:
    >
    > Connect to db:
    > Warning: mysql_connect() [function.mysql-connect]: Can't connect to
    > MySQL server on 'localhost' (10061) in
    > C:\xampp\xampp\ htdocs\home\con n.php on line 19
    > Could not connect: Can't connect to MySQL server on 'localhost' (10061)
    >
    > I connect to this same MySQL server from Tomcat w/no problem.. what is
    > issue here pls...
    >
    >
    > now on top of pg mentioned above, there this description:
    >
    > resource mysql_connect ( [string server [, string username [, string
    > password [, bool new_link [, int client_flags]]]]] )
    >
    > what does 'resource' refer to here pls... and where to do specify what
    > db to connect to... (in java you put db-name in same line where you
    > make the connection..)
    > (and don't you need a driver to connect, I use a JDBC driver to
    > connect w/Java..)
    >
    > would very much appreciate some help.. thank you...
    >
    > Frances
    >[/color]

    Comment

    • Rik

      #3
      Re: connecting to db..

      Frances wrote:[color=blue]
      > this seems pretty straight-forward.. got this code
      >
      > $link = mysql_connect(' localhost:3306' , '<uid>', '<pswd>');[/color]

      Do you need the port here? And I assume your username & password are
      correct?
      What happens if you:
      $link = mysql_connect(' localhost', 'your_username' , 'your_password' );

      If you want to connect by TCP/IP use 127.0.0.1 instead of localhost.
      [color=blue]
      > now on top of pg mentioned above, there this description:
      >
      > resource mysql_connect ( [string server [, string username [, string
      > password [, bool new_link [, int client_flags]]]]] )
      >
      > what does 'resource' refer to here pls...[/color]

      www.php.net > manual > types > resource:


      A resource is a special variable, holding a reference to an external
      resource.
      [color=blue]
      > and where to do specify what
      > db to connect to... (in java you put db-name in same line where you
      > make the connection..)[/color]

      mysql_select_db ('db_name', $link);
      [color=blue]
      > (and don't you need a driver to connect, I use a JDBC driver to
      > connect w/Java..)[/color]

      Mostly it's enabled by default in PHP4, PHP5 it's not, details:


      Grtz

      --
      Rik Wasmus


      Comment

      • Rik

        #4
        Re: connecting to db..

        Frances wrote:[color=blue]
        > when try to connect just from console get error:
        >
        > ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost'
        > (10061)
        > what is this.. what is 10061.. :([/color]

        Try to restart your MySQL-server, if that doesn't work: GOOGLE:


        [color=blue]
        > is it really not possible then to connect to one MySQL server from
        > diff web servers? (I don't think so..) I want to set up my machine
        > so can connect to same MySQL server from Tomcat, IIS, PHP.. (the port
        > thing is also a big pain and don't know if will be able to pull this
        > off..) thank you very much..[/color]

        It should not be any problem to connect dozens of times to the same MySQL
        database from all kinds of locations, servers, applications.

        Rushing into things will give you these kind of errors. You do ask many
        questions. Now, take a break, look at some documentation, google the exact
        questions you have, and discover a wealth of ready information.

        Grtz,
        --
        Rik Wasmus


        Comment

        • Frances

          #5
          Re: connecting to db..

          Rik wrote:[color=blue]
          > Frances wrote:
          >[color=green]
          >> when try to connect just from console get error:
          >>
          >> ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost'
          >>(10061)
          >>what is this.. what is 10061.. :([/color]
          >
          >
          > Try to restart your MySQL-server, if that doesn't work: GOOGLE:
          > http://www.google.com/search?q=mysql+%22ERROR+2003%22[/color]

          I did do a google search earlier.. searched for the same thing...
          I did find one or two fora where it says to restart the server, but
          don't know how you do that.. it says in my book (oreilly) to start the
          server to run $ bin/safe_mysqld --user=mysql &... don't see a file
          called 'safe_mysqld in C:\Program Files\MySQL\MyS QL Server 4.1\bin..
          (why does installation not come with a list of what each executable
          in bin dir does? there are lots of them..)

          I tried to open mysql.exe earlier, saw a glimpse of a shell window,
          which then disappeared.. could this have caused the problem.. it says
          in manual to run 'bin\mysqld --console' I navigated to bin dir and did

          mysqld --console get error.. then did:
          mysqld.exe --console also get error....

          manual says to run bin\mysqld -- there's no such file in bin dir.. this
          is frustrating.. (still don't know what happened.. why after having
          used this server for about a year with no problems would I need to
          restart server all of a sudden..)

          ok, I think I need to switch to mysql newsgroup.. what a pain.. either
          way thank you for your help..

          Frances

          Comment

          • Virginner

            #6
            Re: connecting to db..


            | manual says to run bin\mysqld -- there's no such file in bin dir.. this
            | is frustrating.. (still don't know what happened.. why after having
            | used this server for about a year with no problems would I need to
            | restart server all of a sudden..)

            Use the XAMPP Control Applet, and click on the MySQL START button ;-)

            (you are still using XAMPP?). By-the-way, check earlier thread for more.

            D.


            Comment

            • Frances

              #7
              Re: connecting to db..

              Virginner wrote:[color=blue]
              > | manual says to run bin\mysqld -- there's no such file in bin dir.. this
              > | is frustrating.. (still don't know what happened.. why after having
              > | used this server for about a year with no problems would I need to
              > | restart server all of a sudden..)
              >
              > Use the XAMPP Control Applet, and click on the MySQL START button ;-)
              >
              > (you are still using XAMPP?). By-the-way, check earlier thread for more.
              >
              > D.[/color]

              Virninner, thank you for yr response.. I was trying to connect not to
              MySQL that came w/xampp but to my 4.1 installation that I've been using
              with java for over a year (I want to set everything up so I can connect
              to same db with Tomcat/java, IIS, PHP.. but not getting very far for
              now....;) now cannot connect to db at all, I mean to db I've been using
              for a while, since before I installed xampp.. never had a problem w/it
              before...

              when try to connect just to console get error:

              ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

              (do you think it has to do w/MySQL installation that came with XAMPP
              (although I have uninstalled XAMPP completely by now.... want to
              install it again at some point (I think it's still simpler than
              installing and configuring Apache and
              http://us2.php.net/downloads.php...) separately..) but don't know if
              it's xampp that screwed my MySQL server I had installed... oh brother,
              don't know what to do.. thank you for your help...

              Comment

              • Virginner

                #8
                Re: connecting to db..

                | ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

                .... means simply that the server is not running....

                if it was running, you'd get an error message from the server, like pass
                wrong or something.

                CRTL-ALT-DEL, open task manager and look for it!!!

                D.




                Comment

                Working...