Welcome! Log In Create A New Profile

Advanced

config files with 2 db connections

Posted by 77911997 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
config files with 2 db connections
May 21, 2013 02:55PM
Hey - is it possible to have 1 config file, connecting 2 databases. eg:

Language: PHP
<?php $host="127.0.0.1"; $username="root"; $password=""; $db_name="registration";   //first database called registration with 3 tables. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");   //second database called user with 1 table - user $userdb_name="user"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$userdb_name")or die("cannot select DB");   ?>


I wonder if I read the question correctly:
You then need to add a database user to the table user in the mysql database in phpMyAdmin, giving him certain rights (e.g. add, edit, delete etc), and then link this user to your registration database, in the db table. This user and password is defined in the config file. Google for help on adding database users via phpmyadmin.


1. how do you link tables
2. how do you grant rights in phpmyadmin
3.do we have submit an SQL dump for this table? otherwise how is Mac going to know if we gave rights and linked tables?
4. should he not have users table in his Database or if he creates it differently, the system will crash. worse case is if you lock your pages so that only users who are logged in can use it, he will never see your system running even though he marks the code. but still...
avatar
Mac
Re: config files with 2 db connections
May 23, 2013 08:23AM
Some questions answered elsewhere already.

if you create a $link connection, then a $link2 and so on, you can have as many connections as you want, using the relevant one when required.

A user is required to allow the application to connect to your db - this is specified in the mysql db, which is part of mysql.
Granting rights to this user is explained in the part you quoted (There is another way through the provileges button on the phpMyAdmin home page).This is to allow your application to connect to the database.

Say I require you to have a login to access the application (not the db), you will need a user table inside your db. Alternatively, say you are not allowed to add a user table, the user details can be added to the config file, and the login form can check there. Generally, in real life, one would place such a config file otuside the web root for protection.
Re: config files with 2 db connections
May 23, 2013 09:43AM
You see now!

Now all the nice stuff starts coming out smile

Glen
Sorry, only registered users may post in this forum.

Click here to login