• How do connect to the database because of MySQL extension not available in the latest PHP version using WordPress.

    current WordPress using

    function create_js_html_page() {

    $result = mysql_query(“SELECT DATABASE()”) or die(mysql_error());
    $dbselect = mysql_result($r,0);
    echo $dbselect;

    }

    anybody know how to replace mysql_query to other code because i’m try using mysqli not working. i just want call database name.

    • This topic was modified 9 years, 3 months ago by MammaMia.
Viewing 4 replies - 1 through 4 (of 4 total)
  • What exactly are you trying to do? I recommend using wpdb instead of direct mysql queries. See: https://developer.ww.wp.xz.cn/reference/classes/wpdb/.

    Moderator bcworkz

    (@bcworkz)

    You do not need to connect to get the name of WP’s database.
    echo DB_NAME;

    Thread Starter MammaMia

    (@mizzsuzy)

    hi,

    actually i’m trying connect to external db from wordpress for my custom plugin. currently i’m using script above. after upgrade PHP version, mysql cannot be used. that’s y im trying script to connect external database

    Moderator bcworkz

    (@bcworkz)

    Heh, I figured there was more to your story. Like csloisel said, use the wpdb class like WP does. WP creates a global instance of wpdb to connect with its DB. Create your own instance for your own connection. Then you can use most of the wpdb methods and properties, except for WP specific properties like wpdb::options of course.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘connection external database’ is closed to new replies.