+ Reply to Thread
Results 1 to 6 of 6

Thread: How to connect database?

  1. #1
    cathyf is offline x10Hosting Member cathyf is an unknown quantity at this point
    Join Date
    Dec 2010
    Posts
    2

    Thumbs up How to connect database?

    How to connect and create database at x10hosting?Please I need your suggestions and comments for my thesis project...Thanks!

  2. #2
    techairlines's Avatar
    techairlines is offline x10 Flyer techairlines has much to be proud oftechairlines has much to be proud of
    Join Date
    Jul 2009
    Location
    New York City
    Posts
    2,853

    Re: How to connect database?

    To create the database, see: http://x10hosting.com/wiki/How_to_Cr...abase_and_User

    In your script, use the information you selected when creating the database to connect to the database. The hostname is localhost.
    Best regards,
    Brian Yang - TechAirlines


    How am I doing? Click the star button at the bottom left to rate this post. Thanks.
    Terms of Service | Account Portal | Wiki

  3. #3
    rajat44 is offline Banned rajat44 is an unknown quantity at this point
    Join Date
    Oct 2010
    Posts
    24

    Re: How to connect database?

    <?

    $host="localhost"; // Host name
    $username=""; // Mysql username
    $password=""; // Mysql password
    $db_name=""; // Database name


    //Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
    mysql_select_db("$db_name")or die("cannot select DB");

    ?>
    thats basically it, to connect to the database..

  4. #4
    vv.bbcc19's Avatar
    vv.bbcc19 is offline Community Advocate vv.bbcc19 is just really nice
    Join Date
    Jun 2010
    Location
    India
    Posts
    1,505

    Re: How to connect database?

    mysql_connect("$host", "$username", "$password")or
    die("cannot connect to server");
    will this echo "cannot connect to server" "
    BCV | Community Support Representative
    █ x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  5. #5
    cbirks is offline x10Hosting Member cbirks is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    2

    Re: How to connect database?

    the mysql_connect function connects to the server, mysql_select_db chooses the database and the die("cannot connect to server"); says that if there's an error connecting then it will display the message "cannot connect to server".

    Thanks, Chris

  6. #6
    jbitkill95 is offline x10Hosting Member jbitkill95 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    5

    Re: How to connect database?

    My way of doing it (that's what she said):

    Put this in the page where you want to query, ex. index.php:
    PHP Code:
    <?php require_once('mysqlconnect.php'); ?>
    <?php mysql_select_db
    ("your_db"$mysql);
    $mysql_query sprintf("SQL SYNTAX HERE");
    $mysql_queried mysql_query($mysql_query,$mysql) or die(mysql_error());
    ?>
    Then put this in mysqlconnect.php and change it to 644 permissions (thanks rajat44)
    PHP Code:
    <?php

    $host
    ="localhost"// Host name 
    $username=""// Mysql username 
    $password=""// Mysql password 

    //Connect to server and select database.
    $mysql mysql_connect($host$username$password)or die("cannot connect to server"); 

    ?>
    This way, the user/pass is only readable by the server. Also, you can use the "require_once" for every page, instead of copying user and pass to every page. Also, it's site-wide so when you change the MySQL server, you can change 1 file, and it's site-wide.

    Hope this helps,
    Josh

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 12-01-2010, 09:01 PM
  2. Replies: 1
    Last Post: 06-26-2010, 11:08 AM
  3. Replies: 2
    Last Post: 05-08-2010, 07:52 PM
  4. Replies: 3
    Last Post: 02-08-2010, 04:24 PM
  5. Replies: 0
    Last Post: 11-22-2008, 05:53 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
x10hosting free hosting for the masses
dedicated servers