-1

I was given a task to create a Wordpress Multisite, and to make Wordpress Multisite create tables for each new site inside another database that is made just for that (new) site (let's assume that databases for each site don't have to be created and that they already exist).

I have successfully installed HyperDB and created WP Multisite however I'm still having trouble with the creation of new tables of the site inside the database meant just for the new site.

I managed for tables to be created inside the main database, i.e. for each new site there are specific tables in the main database such as wp_1_posts, wp_2_posts... Unfortunately, that is not the wanted result.

I've been struggling with this thing for quite some time. Anyone having experience with this?

I would be very grateful if someone knows how to do this.

Here is some code. I am not sure of how much it is helpful, but just in case:

 $wpdb->add_database( array(
         'host'     => DB_HOST,
         'user'     => DB_USER,
         'password' => DB_PASSWORD,
         'name'     => DB_NAME,
         'write'    => 1, 
 ) );

 $wpdb->add_database( array(
         'host'     => 'example.host.com',
         'user'     => 'user',
         'password' => 'P455',
         'name'     => 'db_name',
         'write'    => 0, 
         'read'     => 1, 
 ) );
  • Your question is about hyperdb, not wordpress... it sound like you do not understand what and how hyperdb works, so either put more time into reading and understanding the documentation or just read the code as far as I remember there is not that much of it. – Mark Kaplun May 3 '17 at 16:16
  • If by "documentation" you mean the info on the plugin's page then, IMHO, it can't be considered as documentation. If by documentation you meant smth else, give me a link of it. As for the code, which indeed is not that long, examples provided in the comments are not much helpful. I tried to uncomment, edit and add stuff. Nothing was working. That is why I decided to ask a question here. True, I don't understand much, I actually don't even know much about Wordpress, especially HyperDB. If you know about resources that might help, I want to read them. Nothing I googled so far was helpful. – dodo254 May 4 '17 at 9:41
  • @MarkKaplun, you know how to do it? If you do, please show how. I would be very grateful...or do you know? I hope you do... Have you ever done smth like that before? – dodo254 May 4 '17 at 9:48
  • 1.plugins are off-topic here 2. I know the theory I never used it and do not have direct experience with it. 3. This is super advanced stuff. If you can't figure it out you are less likely to be able to maintain such a setting and it is probably better not to use it and just have a stronger DB server. – Mark Kaplun May 4 '17 at 10:03
-2

The plugin you are using hasn't been updated for two years. It is better not to rely on plugins so old. You should consider writing an sql script, that would create a database, as per the MySQL documentation. And simply run the SQL command through php. You can check how that can be done in here: https://www.w3schools.com/PHP/php_mysql_create.asp

After that if your databases are Wordpress databases and you insist on using the wpdb object, you must initiate a new wpdb object. Like so:

$custom_wpdb_object = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );

And use it how it was intended.

  • the scenario for hyperdb is different DB on different servers. You are probably not even going to be able to use php to create DBs in such a setting. – Mark Kaplun May 3 '17 at 16:08
  • As far as I know, the plugin you speak of is the actual plugin which runs on WordPress.com . So being old is irrelevant. – unity100 Feb 12 '18 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.