Yes it’s possible.
The wpdb object can be used to access any database and query any table. Absolutely no need to be WordPress related, which is very interesting.
The benefit is the ability to use all the wpdb classes and functions like get_results
, etc so that there’s no need to re-invent the wheel.
Here’s how:
$mydb = new wpdb('username','password','database','localhost');
$rows = $mydb->get_results("select Name from my_table");
echo "<ul>";
foreach ($rows as $obj) {
echo "<li>".$obj->Name."</li>";
}
echo "</ul>";
Related Posts:
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- What causes the “max_user_connections” warning on WordPress frontend?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Database slowdown after update to 3.4.1
- wpdb_prepare with multiple or condition
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Advanced SELECT query with condtional statements
- Redirecting to old domain after migration website
- Create table from array with prepare
- WordPress running SQL query to update database from form
- Have working sql query… trying to adjust it to use $wpdb
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Trouble running $wpdb->query() with last_insert_id
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- How to connect and insert data in database of wordpress?
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- “BS_” rows in postmeta table
- Where is the HTML-handler part in the wpdb class?
- WordPress Database Query works in phpMyAdmin but not in the code
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- How To connect to the same WordPress database with different database user
- using same mysql user with many databases
- Uploading to WordPress Database
- SQL errors when querying for something with apostrophes
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- phpMyAdmin – Error > Incorrect format parameter?
- Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user ‘root’@’localhost'(using password:YES)
- MySQL Database User: Which Privileges are needed?
- Why is my database import losing text widget data?
- WPDB Insert or if exists Update
- How to return number of found rows from SELECT query
- get_results using wpdb
- Will it break my site if I delete all transient records in wp_options table?
- Checking if Database Table exists
- WordPress (MyISAM) database is slow, should I switch to InnoDB?
- $wpdb won’t insert NULL into table column
- Please explain how WordPress works with MySQL character set and collation at a low level
- The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- Does dbDelta delete columns as well?
- wpdb update add current timestamp not working
- WordPress Database lost auto increment
- Connect to database using wordpress wp-config file
- Reset Post IDs to less than 64bit integer
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- Restoring WordPress posts from database only
- WordPress database scalability from the code perspective
- WordPress Unit Testing – Cannot Create Tables
- Does wpdb add considerable overhead on queries with large result sets?
- Is it possible to define two databases for one installation?
- Why does $wpdb return strings for mysql integer values?
- Does WordPress use the InnoDB engine for MySQL by default?
- $wpdb->prepare() warning in WordPress 3.5
- find a random blogid across my multisite network that has at least one post published
- Slow wp_term_relationships query
- $wpdb->delete column values IN ARRAY()?
- How to use “TRUNCATE TABLE” MySQL statement?
- Inserting data into custom tables
- Hook into $wpdb
- Can I use MariaDB instead of MySQL in wordpress?
- Display data from a non wordpress database on a page template
- How does $wpdb handle COUNT(*)
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- How to close wpdb connection? [duplicate]
- WordPress for a very large website
- What are conventions about the schema of the $table_prefix
- Split WP install between 2 databases?
- WooCommerce with thousands of products – site is very slow – optimize db queries? [closed]
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- Connecting to external oracle database
- Is deleting orphaned wp_options entries safe?
- Is altering a default WordPress database table update safe?
- How to solve slow WordPress site caused by attachment_metadata
- Huge wp_options table
- “MySQL server has gone away” since update to 3.8
- Can’t save ajax value to database
- Delete all post meta except featured image
- Custom DB_COLLATE (collation) value not working on fresh install?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- what to do when your WordPress database is too large?
- Updating all rows of table with $wpdb
- Change all http to https in mysql databse?
- WooCommerce – Query for ordered products
- Large database causes slow load