How to connect to AWS RDS external database (not for the core WordPress db)

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”; … Read more

database interactions using OOP

This is potentially a fairly involved question, so I may not be totally rigorous in my answer, but this should give you a good start when creating and deleting tables.. Include the following lines in your plugin _construct() function of class_my_plugin.php: if (is_admin()){ //manage the the database tables when registering or deactivating register_activation_hook($loc, array($this, ‘your_plugin_installation’)); … Read more

change wp user status from wp_users table

User roles are not stored in wp_user table. They are stored as User Metadata. In wp_usermeta you can find two rows for every user: <prefix>capabilities (for example wp_capabilities) which contains serialized array of roles assigned to that user <prefix>user_level (for example wp_user_level) which contains level of given user. It’s important to remember, that keys for … Read more

WordPress Shortcode show database row

I’m not entirely sure if that’s what you wanted, but… Here’s the code that will register a shortcode, which will get given row and output all the fields of it: function shortcode_db_row_cb( $atts ) { $atts = shortcode_atts( array( ‘id’ => false, ), $atts, ‘db_row’ ); global $wpdb; $row = $wpdb->get_row( $wpdb->prepare( “select * from … Read more