+ Reply to Thread
Results 1 to 5 of 5

Thread: Connecting to a database...

  1. #1
    sathanna is offline x10Hosting Member sathanna is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Australia
    Posts
    60

    Connecting to a database...

    So, I've tried connecting to a database I made... but I can't get the servername right. Apparently, after a little search of the forums, I am not allowed to connect to x10 or whatever to get to my database. I'm confused.

    I've pretty much copy pasted some code I found somewhere to help me connect to the database... looks something like this:

    Code:
    // hostname or ip of server
    $servername='localhost';
    
    // username and password to log onto db server
    $dbusername='myusername';
    $dbpassword='mypassword';
    
    // name of database
    $dbname='my_database';
    
    ////////////// Do not  edit below/////////
    
    connecttodb($servername,$dbname,$dbusername,$dbpassword);
    function connecttodb($servername,$dbname,$dbuser,$dbpassword)
    {
    global $link;
    $link=mysql_connect ("$servername","$dbuser","$dbpassword");
    if(!$link){die("Could not connect to MySQL");}
    mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
    So is it a hopeless cause and I can't use my database at all, or is it something to do with the code? I'm new to php and mysql and whatnot, so I really have no clue.

    Thanks.

  2. #2
    Zubair's Avatar
    Zubair is offline x10 Super Spammer Zubair has a reputation beyond reputeZubair has a reputation beyond reputeZubair has a reputation beyond repute
    Join Date
    Jul 2009
    Location
    Pakistan
    Posts
    8,743

    Re: Connecting to a database...

    make sure you are using correct username and password..

    The correct sytax of username and database is

    DB Name = satha_[dbname]
    USER = satha_[USER]
    Zubair Barkat | Level 2 Tech
    █ 888-X10-9668 - zubair[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004

  3. #3
    sathanna is offline x10Hosting Member sathanna is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Australia
    Posts
    60

    Re: Connecting to a database...

    I'm pretty sure I got that part right. I double checked them and everything. I just edited that out for showing it to people... I don't need the brackets though right?

    what am I meant to put in the servername part so I can connect to the database? =s

  4. #4
    Zubair's Avatar
    Zubair is offline x10 Super Spammer Zubair has a reputation beyond reputeZubair has a reputation beyond reputeZubair has a reputation beyond repute
    Join Date
    Jul 2009
    Location
    Pakistan
    Posts
    8,743

    Re: Connecting to a database...

    Quote Originally Posted by sathanna View Post
    I'm pretty sure I got that part right. I double checked them and everything. I just edited that out for showing it to people... I don't need the brackets though right?

    what am I meant to put in the servername part so I can connect to the database? =s
    Yeah you don`t need to use brackets. replace [dbname] with database name.
    In servername you must enter localhost
    Which is shown correct in the above code.

    Did you add user to database in cpanel??
    Zubair Barkat | Level 2 Tech
    █ 888-X10-9668 - zubair[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004

  5. #5
    sathanna is offline x10Hosting Member sathanna is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Australia
    Posts
    60

    Re: Connecting to a database...

    dang.. I tried localhost. I'm sure everything else is okay. Perhaps everything IS okay...it's just another part that's freaking out.

    After a check, I think it might just be that I am not creating the table correctly... baahhh.. so confusing. :eek4: At least I'm reassured that localhost IS the right thing to put there.

    Thank you. Time to go look up more stuff on creating data and whatnot. :happysad:

+ Reply to Thread

Similar Threads

  1. Replies: 9
    Last Post: 02-18-2010, 08:34 PM
  2. MySQL database not connecting
    By xpressdayton in forum Free Hosting
    Replies: 2
    Last Post: 12-10-2009, 07:41 PM
  3. ASP.NET - Problem connecting to database
    By machado in forum Free Hosting
    Replies: 2
    Last Post: 10-18-2009, 11:12 PM
  4. Error connecting to database
    By flexgrip in forum Free Hosting
    Replies: 3
    Last Post: 08-27-2008, 04:07 AM
  5. connecting to database
    By Daiphron in forum Free Hosting
    Replies: 2
    Last Post: 01-16-2008, 12:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers