I was able to get a working connection using the following code:
function test_connect_to_db() {
$servername="thedatabase.0000000000.location-1.rds.amazonaws.com";
$username="username";
$password = 'password';
$dbname="database";
// Create connection
$conn = new mysqli( $servername, $username, $password, $dbname );
// Check connection
if ( $conn->connect_error ) {
die( 'Connection failed: ' . $conn->connect_error );
}
$sql="SELECT id, firstname, lastname FROM table";
$result = $conn->query( $sql );
if ( $result->num_rows > 0 ) {
// output data of each row
while ( $row = $result->fetch_assoc() ) {
echo '<br> id: '. $row['id']. ' - Name: '. $row['firstname']. ' ' . $row['lastname'] . '<br>';
}
} else {
echo '0 results';
}
$conn->close();
}
add_action( 'init', 'test_connect_to_db' );
Related Posts:
- Getting wrong relationship value in $args in wp_Query?
- How is the data stored in the database?
- Activation hook not creating table
- Is the usage of ON DELETE CASCADE wrong or not allowed on wordpress?
- Version upgrade: can my plugin filter the SQL statements issued during a database upgrade?
- WordPress database error for query INSERT INTO
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Using AND and bracket grouping in SQL not working
- Two different wordpress sites – same server and IP address. Gaining Access to database 1 of 2
- What might be the reason of Couldn’t fetch mysqli_result on another domain?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- WordPress doesn’t create table on plugin activation
- pull data from wordpress database
- How to filter get_adjacent_post()?
- Should I use wpdb prepare?
- Post meta vs separate database tables
- Update Option Stored in Multi-Dimensional Array
- Default table collation on plugin activation?
- How does WordPress handle MySQL row lock errors?
- Writing a plugin that notify my friends of new post that mentions(@) them
- Does using set_transient() function can lead to MySQL problems?
- Not sure the best way to save custom plugin data
- The ideal place for storing persistent PHP objects
- What is the correct way for plugins to create tables with special charset/collation considerations?
- What is the added “complexity” of custom tables?
- Plugin development with unit tests
- Formatting of curly brackets array from WP database to get more readable output
- How to modify post content before writing to database?
- Hello dolly type plugin that allows people to add their own
- Sample — test — data for large WordPress install
- Custom Plugin Database relations
- Database for development
- Is there a naming convention for database tables created by a plugin?
- How to edit mySQL wp_posts table from plugin php?
- Saving data from block editor to the database
- What for the tables ending with the meta used in database of wordpress?
- $wpdb -> Batch insert from XML File?
- Get a custom table to an array
- Subscribe to author?
- I’m designing a plugin to create database indexes. Suggestions?
- How should I store a log for my plugin
- How to create database table, add data, update and delete using wpdb via plugins?
- Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?
- Help With MySQL to WPDB Query Conversion
- Strange issue saving custom field data for a WooCommerce order
- How to perform a heavy and long process in cron jobs?
- Update results, Before deleting the related category [closed]
- Is using custom table to suit business needs instead of transients a big hit to page load speed?
- WordPress Backend HA (Automatic failover)
- mysql_real_escape_string() vs. esc_sql() in WordPress
- dbDelta not installing database
- Is it necessary to do validation again when retrieving data from database?
- What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
- What is the best way to store a few fields?
- Adding columns to core tables
- How to query custom db table?
- Delete data from database using row action
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- $wpdb->prepare with LIKE and sprintf
- wpdb prepare insert table doesn’t work
- DB Query not working in Plugin
- Auto-complete or auto-suggest from stored data in database
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- How do I debug an error that a plugin is causing?
- Save temporary registration data
- Update plugin settings option_name for big plugin update
- What could cause a WP Option to get truncated?
- select a single val though a table in wordpress
- $wpdb->update Issue
- Integrating Custom Database with WordPress
- How to display results from a data table with an encrypted user id?
- dbdelta failing with error: “WordPress database error Table ‘wp_2_myPlugin’ already exists
- Error code when migrate
- Why User_login key doesn’t work with wp_update_user()
- Why is that only the first row getting inserted into Mysql table when i import csv file on backend custom plugin?
- Error Connecting to Database WHEN Installing WordPress on XAMPP [Tried All the Usual Stuff] (Pics Included)
- WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta()
- Is it possible to replace MySQL with JSON files for WordPress
- Use admin-post to submit form data to external database
- Insert Data into Database
- Update database record in plugin
- How to store in the database directly the translation?
- Organising and completing posts (mark as read and hide)
- $wpdb Mysql trigger problem
- Ajax not working to insert, query and result data
- Custom MySQL query to pull out Advanced Custom Fields?
- Associating special meaning with user id 0
- $wpdb how can i save my postmeta table before querying it
- What method should I use to store my plugin data (multi level menus with options on each item)
- How to add additional field in a table row after creating a table?
- WordPress plugin tables become corrupt
- Post data in wp-admin to external database
- How can I get a plugin to hook ‘dbdelta_queries’ — a filter used during version update?
- How can I delete the options from DB when the plugin is deleted?
- How to create a database table in WordPress using PHP
- Can I log the searches that are returning 404 in the DB?
- Programmatically creating posts based on external JSON feed (asynchronously)
- Making a user platform reachable by a qr code on a pin-back-button [closed]
- multiple record insert creating many duplicate records