Connect to other Data Base in Subs-Post.php

Started by MacX, October 23, 2007, 12:52:57 PM

Previous topic - Next topic

MacX

Hello.

I posted this also in other section some days ago, but i think i posted it in wrong place, so i do it here now, i hope you can help me.

I want to do some actions ones a user has posted a message.
So i go to Subs-Post.php file and just after the sql code to insert the message data into the forum data base, i want to insert other information in other data base.

I have tested it inserting the information i want into the same data base the forum has. But i prefer to insert it into other one.

I use this to connect to a new data base:

mysql_connect("mysql.mywebpage.com","db_name","db_pass");
mysql_select_db("db_name");


But, ones i do it, when i post a message in the forum it appears an ERROR.
The message is not posted and it says something like...
QuoteIt seems that your data base can need an update. The forum files version  are in SMF 1.1.4, while your data base is in SMF 1.10 version. We recommend you to execute the last version of upgrade.php

The problem is not really that. I mean, if i dont try to connect to a new data base to insert some information i want, there isnt that problem and all runs good.
The problem is that i try to connect to a new data base in Subs-Post.php

Can someone help me with this?
How can i connect to a new data base to do some actions in it and then continue in the forum data base?

I paste here the part of the code when i try to do some actions:
In line 1512 of Subs-Post.php
Quote
// Insert the post.
   db_query("
      INSERT INTO {$db_prefix}messages
         (ID_BOARD, ID_TOPIC, ID_MEMBER, subject, body, posterName, posterEmail, posterTime,
         posterIP, smileysEnabled, modifiedName, icon)
      VALUES ($topicOptions[board], $topicOptions[id], $posterOptions[id], SUBSTRING('$msgOptions[subject]', 1, 255), SUBSTRING('$msgOptions[body]', 1, 65534), SUBSTRING('$posterOptions[name]', 1, 255), SUBSTRING('$posterOptions[email]', 1, 255), " . time() . ",
         SUBSTRING('$posterOptions[ip]', 1, 255), " . ($msgOptions['smileys_enabled'] ? '1' : '0') . ", '', SUBSTRING('$msgOptions[icon]', 1, 16))", __FILE__, __LINE__);
   $msgOptions['id'] = db_insert_id();
   
/* ****************Here i start my conection****************** */
      

  mysql_connect("mysql.mywebpage.com","db_name","db_pass");
  mysql_select_db("db_name");


Thx a lot.

PD: sry for my english  ;)

KGIII

Quote from: MacX on October 23, 2007, 12:52:57 PM

I want to do some actions ones a user has posted a message.

Instead of telling us how you want to do it why not tell us what you're trying to get done and then someone may have found a way to do it already and be able to help you.

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

MacX

Because thats not the point.
I mean, it doesnt mind what i want to do, i know how to do it.
I only want to insert some data on a database, and i know how to do it if i do it in the same database the forum is.

The only problem i have is that i dont know why, the forum doesnt allow me to make a conection with a different database.

If you help me making it to connect to a database, i have the problem solved. Is only that. The conection with a database,  as you can see in the post title.

Just i make a conection with other database, the error appears.

Thx for the answer.

JayBachatero

What function are you using to insert the data to the other database?  db_query?  What I would suggest you do is give the SMF user access to the other database and in the query the something like.


db_query("
        INSERT INTO `db_name`.table
        ...", __FILE__, __LINE__);
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

MacX

Lots of thx JayBachetero.
That was not the solution, but you gave me an idea about it.

I was using db_query without the __FILE__, __LINE__.
Although i used it, it didnt work.

So i tryed to do it with mysql_query, and it worked.
So thx for the idea man. It was a simple error, but as i saw the forum used db_query to connect...

Thx.

JayBachatero

db_query uses a connection link resource so you can only use one connection.  So you need to use mysql_query and provide it a link resource.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Advertisement: