How do you use 1 database for multiple php scripts?

This Question From PHP Scripts | 2 Answers


QUESTION:

Ok, so i have a lot of different php scripts like user management, shopping cart, forums. I don’t want my customers to have to sign-up multiple times for my website. I need to know how to do this.

Thanks A lot

2 Comments so far

  1. Nigel on June 3, 2010 10:13 pm

    You only need the one database, you can connect to it from as many scripts as you want.
    Each script will have something like ( for MySQL )

    $conn = mysql_connect($dbhost, $dbuser, $dbpass)
    or die (’Error connecting to mysql’);

    Have a look at http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/connect-to-mysql-database.aspx for more examples.

  2. temp on June 3, 2010 10:22 pm

    Everytime the user restarts the browser/tab, it is sure that he/she must login again (just informing).
    For your problem, you must use the global variable $_COOKIE (good tutorial link: http://www.w3schools.com). This way the server will remember the user. $_SESSION may also be a great help. And you must ensure that each sript will have access to a script responsible for staying the database connection alive (a simple way to do it). It will be very long if I’ll tell you everything but I guess you will get some ideas with this answer…..just look for cookies and sessions.




Powered by Yahoo! Answers


Licenced Practical Nursing Programs - Support WordPress
You can syndicate both the entries using RSS Feeds and the Comments Feed