Wednesday, February 9, 2011

How can I re-use an existing database connection in phpBB3?

I am using my own db for phpbb3 forum, and I wish to insert some data from the forum into my own tables. Now, I can make my own connection and it runs my query but in trying to use the $db variable(which I think is what you're meant to use??) it gives me an error.

I would like someone to show me the bare bones which i insert my query into to be able to run it.

thanks

  • Well.. You haven't given us very much information, but there are two things you need to do to connect and query to a database.

    For phpbb, you may want to read the documentation they have presented:

    http://wiki.phpbb.com/Database_Abstraction_Layer

    Here is a general overview of how you'd execute a query:

    include($phpbb_root_path . 'includes/db/mysql.' . $phpEx);
    
    $db = new dbal_mysql();
    // we're using bertie and bertiezilla as our example user credentials. You need to fill in your own ;D
    $db->sql_connect('localhost', 'bertie', 'bertiezilla', 'phpbb', '', false, false);
    
    $sql = "INSERT INTO (rest of sql statement)";
    
    $result = $db->sql_query($sql);
    
    From Cetra
  • I presumed that phpBB already had a connection to my database. Thus I wasnt going to use a new one? Can i make a new one and call it something else and not get an error?

    And $resultid = mysql_query($sql,$db345);

    Where $db345 is the name of my database connection

    Omar Kooheji : If php is like any other database I've used then you should be able to have as many connections as the database suports. Which is usually greater than 1.
    Chris : Yeah, got it. thanks to all of you for your help!
    From Chris

0 comments:

Post a Comment