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
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- WordPress (MyISAM) database is slow, should I switch to InnoDB?
- WordPress Database lost auto increment
- Slow wp_term_relationships query
- How to use “TRUNCATE TABLE” MySQL statement?
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- WordPress for a very large website
- WooCommerce with thousands of products – site is very slow – optimize db queries? [closed]
- WooCommerce – Query for ordered products
- Query WordPress database by registered date and role
- Tons of Twitter rows in my database
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- Set Display Name to first and last name (phpmyadmin SQL Query)
- Does WordPress ever need multiple databases?
- Why are no posts showing despite my apparently correct DB restoration?
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- Select Multiple meta_value from WP DB; Single Query
- Cannot update custom database table row
- Is it possible to split database tables using HyperDB?
- Order by custom table and multiplication
- What happens if I overwrite the current wp_options table with a backup from a week ago?
- SQL Error wp_commentmeta – incorrect table definition
- CRUD operations using WordPress database API
- Multiple wp_options tables to share content across installs
- Select two sums with single get_var statement
- How to Mirror WordPress database from Remote server to Local server
- Is MariaDB’s Aria storage engine suitable for WordPress?
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- How do I query wp_options for expired transient pairs with MySQL commands?
- How to fix database error duplicate entry
- Migration: Copying database content to a different server
- How do I convert a MySQL database from utf8mb4 to utf8 encoding?
- WPDB SQL query with prepare() returning variable, not db value
- Remove empty rows from the database
- Why this query is not showing any result on wordpresss home page?
- CreateOrUpdate in WordPress
- How to get a list of WordPress default database tables?
- Using $wpdb | checking entered email against existing emails in db
- Optimizing function that automatically creates internal links based on post title string
- How to get product order by two custom taxonomy in wordpress
- Get results from wordpress data custom table
- Outputting query results
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- Creating and Using Tables in the WordPress Database
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to insert a value to decimal type field using wpdb->prepare?
- I wanted to Know that how can I give ingore to 0000-00-00 in my config file
- Set a cron job to delete a specific database table table every midnight
- How to import products in host instead of database on wordpress?
- next comment id number wordpress
- Correct and secure way to access a custom SQL database in a custom PHP template file
- Merging development site with live site
- Missing latest posts and options after DB migration via phpMyAdmin
- Check if a database is well installed
- live site do not update after importing sql database
- Write mysql credentials in plugin
- How do i get value from wp_postmeta?
- How can I retrieve data from alternate database using wpdb class?
- “MySQL server has gone away” since update to 3.8
- featured image not showing up with mysql_connect
- MySQL Database User: Which Privileges are needed?
- Import Excel (or csv) Table with user-data as subscribers to wordpress
- SQL query : Select a thumbnail for a media
- How to delete field using WPDB?
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- WordPress database connection failed, while mysql client is working [closed]