This topic is locked

phpr 3.11

4/25/2007 11:13:45 AM
PHPRunner General questions
P
ploppy author

hi
is it possible to connect to more than 1 databasde at the same time. example, when a customer registers on my site it is read into mysql as filed email and field lastname. i created a new db in phpr and would like to read member info from this database and the data from the new database. is this possible? many thanks.

kujox 4/25/2007

hi

is it possible to connect to more than 1 databasde at the same time. example, when a customer registers on my site it is read into mysql as filed email and field lastname. i created a new db in phpr and would like to read member info from this database and the data from the new database. is this possible? many thanks.


yes it is but not using phprunners settings, you'll need to setup another connection and just the php/mysql standard functions

function get_db2_data($id) {

$db2 = mysql_connect("localhost", "user", "password");

mysql_select_db("db2_name",$db2);

$sql2 = "SELECT * FROM table WHERE id=". $id;

$result2 = mysql_query($sql2,$db2);

$datarow = mysql_fetch_array($result2);

return $datarow;

}
then just call it by
$new_data = get_db2_data($id);


and your data from the other db is in the array $new_data

P
ploppy author 4/26/2007

Thx kujox. where do i place this code in phpr? could you give me example please. thx very much.

kujox 4/26/2007

just place it below where you need to access the 2nd database
ie

// standard event function

function AfterSuccessfulRegistration()

{

//********** Custom code ************

// put your custom code here

}
// 2nd db connect function

function get_db2_data($id) {

$db2 = mysql_connect("localhost", "user", "password");

mysql_select_db("db2_name",$db2);

$sql2 = "SELECT * FROM table WHERE id=". $id;

$result2 = mysql_query($sql2,$db2);

$datarow = mysql_fetch_array($result2);

return $datarow;

}


and put the call to the function where you need the data

P
ploppy author 4/26/2007

thx kujox. still a bit confused. where does this command need to be placed?

and put the call to the function where you need the data


i do not need people to register, they already have done that from 2nd database. i create a new database with login but when i do, it dosen't see the 2nd database so i have to take my login data from new database which dosen't have any. so, what i would like to achieve is to create a new db, use the login option from database, but take it from the 2nd database where the login info is, and not the new one. does that help? thx

kujox 4/27/2007

thx kujox. still a bit confused. where does this command need to be placed?

i do not need people to register, they already have done that from 2nd database. i create a new database with login but when i do, it dosen't see the 2nd database so i have to take my login data from new database which dosen't have any. so, what i would like to achieve is to create a new db, use the login option from database, but take it from the 2nd database where the login info is, and not the new one. does that help? thx


Put the $new_data = get_db2_data($id); in the event where you need the data
Do you create the 2nd record manually? It sounds like you are creating work for yourself.
Which do they register in?