This topic is locked

Insert data in another data base

1/12/2011 11:05:01 AM
PHPRunner General questions
M
mcasassus author

Hello,
Some of you know a solution to insert data into another database ?
My problem is to insert content from my application, to the table of contents for joomla ...
In practical terms, part of the problem is to connect simultaneously to one or more external databases.
I appreciate the help to solve this
Mario

Sergey Kornilov admin 1/12/2011

As a first step I suggest to check PHPRunner/Joomla integration article:

http://www.asprunner.com/forums/topic/13251-phprunner-and-joomla/
You can also connect to another database and perform an update:

$host="localhost";

$user="username";

$pwd="password";

$sys_dbname="database";

$conn = mysql_connect($host,$user,$pwd);

if (!$conn || !mysql_select_db($sys_dbname,$conn))

{

trigger_error(mysql_error(), E_USER_ERROR);

}

db_query("update sometable set somefield='some value'", $conn);
M
mcasassus author 1/13/2011



As a first step I suggest to check PHPRunner/Joomla integration article:

http://www.asprunner.com/forums/topic/13251-phprunner-and-joomla/
You can also connect to another database and perform an update:

$host="localhost";

$user="username";

$pwd="password";

$sys_dbname="database";

$conn = mysql_connect($host,$user,$pwd);

if (!$conn || !mysql_select_db($sys_dbname,$conn))

{

trigger_error(mysql_error(), E_USER_ERROR);

}

db_query("update sometable set somefield='some value'", $conn);



Hello Sergey,
Thank your for your reply, I try the connection and she work ok, but when I try to put this code
[size="3"]/****/
$host= "(SELECT Dabase name.Table 1.Field 1 FROM Dabase name.Table 1 ORDER BY Dabase name.Table 1.id DESC LIMIT 1)";

$user= "(SELECT Dabase name.Table 1.Field 2 FROM Dabase name.Table 1 ORDER BY Dabase name.Table 1.id DESC LIMIT 1)";

$pwd= "(SELECT Dabase name.Table 1.Field 3 FROM Dabase name.Table 1 ORDER BY Dabase name.Table 1.id DESC LIMIT 1)";

$sys_dbname= "(SELECT Dabase name.Table 1.Field 4 FROM Dabase name.Table 1 ORDER BY Dabase name.Table 1.id DESC LIMIT 1)";
/****/

[/size]

for connect my apply with joomla I receive one PHP error "mysql_connect() [function.mysql-connect]: Unknow My SQL server host"...
the data in this select request is exactly the same if as you put in your example :
"localhost"

"username"

"password"

and

"database"
all work fine if I dont use the select request, but for my appli I need to put inside of the appli the possibility to change by the user the data for each Joomla connection, I try by many ways but I dont find the solution.
If you or some one in this forum know how can do this, thank you very much for your help
Mario

Sergey Kornilov admin 1/13/2011

I'm afraid I don't understand. host, user, pwd fields should contain MySQL host, username and password that are the same for all users. I don't understand why you trying to put SQL query there.

M
mcasassus author 1/13/2011



I'm afraid I don't understand. host, user, pwd fields should contain MySQL host, username and password that are the same for all users. I don't understand why you trying to put SQL query there.


Hello Sergey,
I work in one appli for manage some contents for a lot off different sites using Joomla (one enterprise with many sites Joomla) and they want to use only one back office for manage the flow content.
Actually my appli manage the workflow for many publications at the same time (but in this case all is in my data base).
The problem is to continue to manage the paper publications and send by the way some of this contents in the magazines to his web sites.

I create for doing this, one table to store the infos, for the connections to the different s servers Joomla to this sites, and then the user can select the site he want for sending the content.
For this reason I searching one solution for stay connected to the database PHPRunner for the big work, and also to have the possibility to do inside the appli the connection to the others databases

for sending some contents to the web and not only for the paper magazines.
For this reason I thinking, if I put SQL at this place, the user can change the database ID or I put one "where" condition for select the desired database.

If this is correct, by this way the connection become possible with different servers adresses. But this SQL create a PHP error ... I don't arrive to find how to put this SQL is this place...
One last question :
Is there the possibility of opening two (or more) separate connections to two different MySQL databases in different host and user passwords via php?

For example, a connection to a local mysql server (intranet) and other parallel simultaneous connections to other servers mysql on the Internet?



I hoppe I arrive to explain better my problem.
Thank you for your help
Best regards

Mario

Sergey Kornilov admin 1/14/2011

Mario,
sorry, I still don't get it.
Answering your question in bold - it's possible to connect to another database in PHP code. Supplied code snippet does just that.
Probably you can show us your website internal structure to provide a better understanding of what you trying to achieve.