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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Location
    San Antonio, Tx
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    newbie question: how do i connect to my database?

    i went into my hosting control panel, created a database, and now want be able to use it. for instance i'm in the process of setting up a login system. it needs to use a database. the first step of the tutorial is to execute a command that sets up a table - how do i do this? where do i execute the command in? do i need any type of software?

    site is www.bluefishwebsitedesign.com used php for the first time to setup the forms on the contact page and design proposal page



    ty

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    You'll most likely need to either use SSH to login to the computer and use mysql via the command line, or have phpMyAdmin installed and use that.

    To use PHP to connect to a mysql database, check out the php.net documentation here:

    http://us2.php.net/manual/en/ref.mysql.php

    Or w3schools at:

    http://www.w3schools.com/php/php_ref_mysql.asp

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Can you already view PHP pages on your computer? If not I recommend you download and install WAMP from http://www.wampserver.com/en/download.php

    That will install an APACHE server onto your local system so you can view PHP files and also PHP 5. It also includes PHPMyAdmin which you can use to create a database. In the phpmyadmin setup you can set up a username and password to access the database you have created. If you don't give anything a username and password then I think the master username would be 'root' but I'm not sure of the password, if any.

    The code you would then place in you php file would be as follows

    PHP Code:
    $host "localhost";
    $database "your_databases_name";
    $username "your_username";
    $password "your_password";

    mysql_connect($host,$username,$password) or die ("Could not connect to the host");
    mysql_select_db($database) or die ("Could not connect to the database"); 
    I hope that is of some help at least.

  • #4
    New to the CF scene
    Join Date
    Nov 2006
    Location
    San Antonio, Tx
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just got off work and going to give the above two replies a try..

    TY for your help littlejones and bcarl

    lates

  • #5
    New to the CF scene
    Join Date
    Nov 2006
    Location
    San Antonio, Tx
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    man guys im kind of confused on a basic level. my domain is setup with php. i have multiple php functions working on my site, such as a form script to send a design proposal then another one for a contact page. i went into my control panel for my site and created a new database - a MySQL database named "datamain".

    but this throws me; how do i add a table to that an existing database?

  • #6
    New to the CF scene
    Join Date
    Nov 2006
    Location
    San Antonio, Tx
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    like

    http://www.w3schools.com/sql/sql_create.asp


    i'm not sure even where to start.. it tells me what the commands are, but how do i execute them? do i include them on a page in my website? ive read through several tutorials and sort of have a grasp on everything except this very first step! pls help, any is appreciated

  • #7
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by drake2851 View Post
    like

    http://www.w3schools.com/sql/sql_create.asp


    i'm not sure even where to start.. it tells me what the commands are, but how do i execute them? do i include them on a page in my website? ive read through several tutorials and sort of have a grasp on everything except this very first step! pls help, any is appreciated
    drake, the easest way to work with tables (imho) is using PHPMyAdmin easy to install and use it has an area were you can execute sql commands or you can use the interface to setup tables and such. Check out http://www.phpmyadmin.net/home_page/index.php
    to down load a copy. you will need to install this on your host to work with your Mysql tables on your host (your server may provide this or another utility to manage MySQL aslo)

    Side Note: I installed PHPMyAdmin on my local PC, then uploaded (FTP'd) to my host. Good idea to have MySQL and PHPMyAdmin running on your local pc for testing if thats were you do all your development work at.
    Last edited by musher; 11-13-2006 at 05:46 AM.
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #8
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    But if you were going to use the database you already created then you are correct in saying that you need to create a php page with the create table statement within it. You only need to do this once so you might aswell call it "tables.php" and then discard it after use (or store it elsewhere).

    So all you need to do is use the syntax I showed you above to connect to the database (the host would no longer be 'localhost' as it is on your hosts server - you'll have to figure that one out). I'm not sure if there is a default username and password if you haven't set one. My guess would be username 'root' and no password. In other words...

    PHP Code:
    $host "your_host";
    $database "your_databases_name";
    $username "root";
    $password "";

    mysql_connect($host,$username,$password) or die ("Could not connect to host"); 
    ...and then the rest of your code.

    I hope that help clarifies it somewhat.


  •  

    Posting Permissions

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