Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    Newport Beach, California
    Posts
    96
    Thanks
    11
    Thanked 1 Time in 1 Post

    newbie connect to mysql database

    hi.

    learning php.

    at part where we connect to database.

    2 questions.

    1. tutorial has me using "localhost" as 1st argument in mysql_connect, with wamp server on local machine. will i need to change this to my domain name when moving files to production site? .. or will "localhost" still work there?

    2. tutorial has me establishing connection mentioned above using "root" user. then in step #2, they select the database. but wouldn't it be better to connect using the desired db, instead of root, by using login credentials for the desired db?

    i have vps, and when i create new db in cpanel, i create user name and passwod for each particular database.

    feels weird establishing a root connection. i always used to working with database-specific user name and password.

    no where do i ever enter the db-specific user name and pw it seems.

    do you follow me?

    guidance?

    i would prefer to user db-specific credentials, not root.

    then it would seem like i don't have to specify the db in step #2. (db_select)

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by PonchoX View Post
    1. tutorial has me using "localhost" as 1st argument in mysql_connect, with wamp server on local machine. will i need to change this to my domain name when moving files to production site? .. or will "localhost" still work there?
    Depends on your host. Some hosts allow localhost, others don't. They should tell you.

    Quote Originally Posted by PonchoX View Post
    2. tutorial has me establishing connection mentioned above using "root" user. then in step #2, they select the database. but wouldn't it be better to connect using the desired db, instead of root, by using login credentials for the desired db?
    Again, depend on the host if they'll let you use root, but regardless, you shouldn't use root, because if someone gets in, they'll be able to mess with all the dbs root has access to.

    Even if you use a db specific username/pass, you'll still have to select the db... the server doesn't know what db you're trying to access when you enter a user/pass, just what dbs that user/pass have access to.
    Last edited by Keleth; 06-23-2010 at 08:02 AM.

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    31
    Thanks
    10
    Thanked 0 Times in 0 Posts
    It might be something like

    PHP Code:
    <?php 
    $username
    ="cpannelusername";
    $password="cpannelpassword";
    $database="cpannelusername_databasename";
    mysql_connect(localhost,$username,$password) or die(mysql_error()); 
    mysql_select_db("$database") or die(mysql_error());
    But like Keleth said, this depends on your host.
    Last edited by Craigy; 06-23-2010 at 01:34 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •