Find the answer to your Linux question:
Results 1 to 4 of 4
I'm starting a project where I'll be making a Movie database. I want it to be accessable over the web. How would I communicate with the database using PHP. Also ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314

    Talking with a data base using PHP


    I'm starting a project where I'll be making a Movie database. I want it to be accessable over the web. How would I communicate with the database using PHP.

    Also what would be the best method to implement user login.
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

  2. #2
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    You have a much functional API in PHP to communicate with many kind of databases. The best way to se the syntax of what kind of database you shall use is to look at the php manual.. look here http://se2.php.net/manual/en/... To connect to a mysql-database, you do like this for example...

    Code:
    $link = mysql_connect("$HOST", "$USER","$PASS") or die ("Could not connect to DB");
    mysql_select_db("$DB") or die ("Could not select database:$DB check username or password or if database are up and running\n");
    
    $query = "select * from my supertable";
    $result   = mysql_query($query) or die ("Failed to execute SQl-query\n");
    Fo user authentication you can write your own in php if you like or use apache:s authentication if you are using an apache-webbserver.

    Good luck...just post if you get in to trouble..
    Regards

    Andutt

  3. #3
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314
    Alright thanx for the direction now I have a question about sessions and cookies. I want to have users log into the web page. So should I just use a users table that will have a users name and password. How would I check to make sure they loged in with the right pass and name. Also How can I make it so that when they leave and come back They will still be logged in.
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    The easiest approach is indeed to create a table which stores usernames and (optionally encrypted) passwords. When authenticating users, just compare what they gave in the login form with what is in the database. Then create a session using something like the following:
    Code:
    session_start();
    $_SESSION["username"] = $_POST["username"];
    After that, you can check the existence of a valid session by checking the value of $_SESSION["username"]. Remember that you must call session_start() on each page that wants to use the session data.
    See http://www.php.net/manual/en/function.session-start.php for more info.

Posting Permissions

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