Title: connection external database
Last modified: March 10, 2017

---

# connection external database

 *  [MammaMia](https://wordpress.org/support/users/mizzsuzy/)
 * (@mizzsuzy)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/connection-external-database/)
 * 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](https://wordpress.org/support/users/mizzsuzy/).

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

 *  [csloisel](https://wordpress.org/support/users/csloisel/)
 * (@csloisel)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/connection-external-database/#post-8896844)
 * What exactly are you trying to do? I recommend using wpdb instead of direct mysql
   queries. See: [https://developer.wordpress.org/reference/classes/wpdb/](https://developer.wordpress.org/reference/classes/wpdb/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/connection-external-database/#post-8897019)
 * You do not need to connect to get the name of WP’s database.
    `echo DB_NAME;`
 *  Thread Starter [MammaMia](https://wordpress.org/support/users/mizzsuzy/)
 * (@mizzsuzy)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/connection-external-database/#post-8897105)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/connection-external-database/#post-8899870)
 * 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.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/connection-external-database/#post-8899870)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
