Connect another DB and fetch records from some tables

here is what I did with slight change as per your need. May be it will helpful for you. 🙂 function fetch_news() { global $wpdb; $wpdb_backup = $wpdb; // backup existing instance $wpdb = new wpdb( NEWS_DB_USER, NEWS_DB_PASSWORD, NEWS_DB_NAME, NEWS_DB_HOST ); // create new db instance wp_set_wpdb_vars(); // add variable $news_sql = $wpdb->get_results(“SELECT * FROM … Read more

Migrating from Existing MySQL Setup to WordPress

If you’re fairly well-versed in WordPress plugin development, you could write a couple plugins, one to create your users with wp_create_user(), and another to insert your articles as Posts using wp_insert_post() (which, among other things, allows you to specify the post_author on each post that you insert). If you’re not so comfortable writing plugins, then … Read more

WordPress with php5-fpm and nginx

Ah, my problem ended up stemming from an issue with php5-fpm. Essentially, there were php5-fpm services running that were “old” and thus when I tried to access mysql from the web, it wasn’t detected. But when I tried to access it via cli, it was detected. That narrowed it down to php5-fpm for me, and … Read more

Mysql SELECT posts

I resolved creating SQL query: SELECT posts.post_title, posts.post_content, trans.element_type, trans.language_code FROM wp_posts AS posts INNER JOIN wp_icl_translations AS trans ON posts.ID = trans.element_id INNER JOIN wp_postmeta AS meta ON posts.ID = meta.post_id WHERE trans.element_type=”post_product” AND trans.language_code=”de” This is added only if you need something on post_meta: … INNER JOIN wp_postmeta AS meta ON posts.ID = … Read more

Deprecated: mysql_connect():

The MySQL extension: Is not under active development Is officially [deprecated][1] as of PHP 5.5 (released June 2013). Has been removed entirely as of PHP 7.0 (released December 2015) Lacks an OO interface Doesn’t support: Non-blocking, asynchronous queries [Prepared statements][2] or parameterized queries Stored procedures Multiple Statements Transactions The “new” password authentication method (on by … Read more

PHP script can’t connect to Database on port 3307

Try this one. This is connection object created to use in wordpress $mydb = new wpdb( ‘username’, ‘password’, ‘my_database’, ‘localhost’ ); and if it is way that you want to go check in codex $wpdb function ‘select’ to select database when do queries. Hope it help.

Can’t find my wordpress DB in phpmyadmin

I don’t see any reason to login as root if you only need the one database… Have you tried logging in to phpMyAdmin as the user with the same credentials as your WordPress installation? user: bn_wordpress pass: 0cca6aaab5 port: 3306 We could avoid phpMyAdmin all together… From the command line you can dump the database … Read more

Unknown collation when I import a dump from an existing site into a development database?

This issue is as a result of your server not supporting the utf8mb4_unicode_520_ci collation type. To resolve this you should convert the collation for all tables with utf8mb4_unicode_520_ci to utf8_general_ci If you’re exporting through phpmyadmin, you can: Click the “Export” tab for the database Click the “Custom” radio button Go the section titled “Format-specific options” … Read more

Set meta_key and meta_value for all registered user in wordpress using sql query [closed]

Add this code in functions.php. visit your site you, it will automatic add/update all user meta value. After executing this code just comment out or remove this code. $args = array( ‘fields’ => ‘all’, ); $blogusers = get_users( $args); foreach($blogusers as $key => $user){ update_user_meta( $user->ID, ‘is_activated’, 1 ); } OR you can also do … Read more

Can Someone Help Me Fix This WordPress Missing Argument Error?

As it says in wpdb::prepare Prepares a SQL query for safe execution. Uses sprintf()-like syntax. Thus, if you change it to: $sql = $db->prepare(“SELECT ap.photo_id, ap.creation_date, ap.owner_id, ap.file_id, ap.title AS photo_title, ap.description, aa.album_id, aa.title AS album_title, aa.category_id, sf.storage_path, u.displayname, u.username FROM engine4_album_photos ap LEFT JOIN engine4_album_albums aa ON aa.album_id = ap.album_id AND category_id <> 0 … Read more