PDA

View Full Version : How to use currect vB db connection?


CoffeeLovesYou
01-21-2013, 10:24 PM
Hi,

In all of my scripts, I have the mysql connection, as well as the selection of the mysql database.

However, the connection and the database is the same one defined in the vBulletin config.

My plugins are all using global_start.

How can I erase my db connection from my script to use the one vB is already using?

Sample script I am using:


ob_start();
?>
<center><?php
//this is the same as my vBulletin's db connection info in config.php
$link = mysql_connect("localhost","user","password");

mysql_select_db(databasename);
?>

<html>
<body>

<?php

$sql = mysql_query("my query here");
//stuff here
echo "hi";
?>
</html></center>
<?php
$countsrr = ob_get_contents();
ob_end_clean();

Simon Lloyd
01-22-2013, 03:35 AM
if you are running the queries from within vbulletin then you have an open connection to the database already and can just run your query, if they are scripts outside of vbulletin then maybe try require_once('./includes/config.php');

CoffeeLovesYou
01-22-2013, 08:07 PM
Wow ,I feel like an idiot.
Removed my link and db select from the plugin and it's working like a charm.

Thanks!

Simon Lloyd
01-22-2013, 09:13 PM
Its only ever easy if you know the answer :) - you're welcome!