• i have in this function that i would use like a plugin the connection to the db:

    function rate($id) {

    $dbhost = 'localhost';
    $dbuser = 'user';
    $dbpass = 'password';
    $dbname = 'wordpress';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    mysql_select_db($dbname);

    $tableName="test";

    If i use this like a plugin is not necessary create the db connection, right ? And if the same plugin have another file that call the db, what i do ?

Viewing 1 replies (of 1 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Huh?

    If the php code is running as part of wordpress (like a plugin would be), then just add global $wpdb; to the top of the function and you have the DB connection through the wpdb object.

Viewing 1 replies (of 1 total)
  • The topic ‘how make a plugin with the db connection’ is closed to new replies.