Support » Developing with WordPress » How to use wp database in custom plugin

  • Resolved scriptbooster

    (@scriptbooster)


    Hi, Sir I want to know how to connect wordpress database to my require place
    Like I want to connect Same WP DataBase
    With mysite.com/db.php
    I require
    private $servername = “localhost”;
    private $username = “xxx”;
    private $password = “xxx”;
    private $dbname=”xxx”;

    These Things In A plugin I ready the plugin problem is I not want to go and manually set this and I am not a pro level developer Can you Make A Code Which I will replace with above code that get these things no need to set in files every time .

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Rep

    You’d use the wpdb class to access your database.

    Thread Starter scriptbooster

    (@scriptbooster)

    Sir, That’s the problem I don’t know how to do it
    private $servername = “localhost”;
    private $username = “xxx”;
    private $password = “xxx”;
    private $dbname=”xxx”;
    Can you type code I will replace with this .

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Rep

    No, I can’t, because it would only be a small part of a much larger plugin. If you need custom coding, you need to hire someone. We recommend jobs.wordpress.net; do not accept any offers from people who post here, and be sure to check out references for anyone you might want to hire.

    Thread Starter scriptbooster

    (@scriptbooster)

    site/db.php
    site/user/db.php
    site/wp-content/plugins/hero/index.php

    I need that code in these files

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Rep

    no,you do not. You set your wp database info in only ONE place, wp-config.php.

    Thread Starter scriptbooster

    (@scriptbooster)

    I think sir you not understand
    Read this

    site/db.php
    site/user/db.php
    site/wp-content/plugins/hero/index.php
    These are files required belew code

    private $servername = “localhost”;
    private $username = “xxx”;
    private $password = “xxx”;
    private $dbname=”xxx”;

    I am doing it manually by cpanel

    I want this code connect to wp-config.php
    Database details
    So me not need to do it manually

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Rep

    I don’t think you understand how WordPress works. If you want to integrate something with WordPress, you’d write a plugin. You do not go around edit PHP files directly.

    You’re asking about how to develop a plugin. See https://developer.wordpress.org/plugins/

    Please tell me what you are really trying to accomplish instead of asking about the database.

    Thread Starter scriptbooster

    (@scriptbooster)

    Ok

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to use wp database in custom plugin’ is closed to new replies.