Title: WP Session creates database error
Last modified: December 15, 2017

---

# WP Session creates database error

 *  Resolved [therealgilles](https://wordpress.org/support/users/chamois_blanc/)
 * (@chamois_blanc)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/)
 * Hello,
 * I just updated to v2.0.1 and I am getting lots of database errors. Something 
   is very wrong. Please advise/fix. Thank you!
 *     ```
       [15-Dec-2017 02:55:56 UTC] WordPress database error Table 'dnvxwyxfcy.wp_sm_sessions' doesn't exist for query SELECT * FROM wp_sm_sessions WHERE session_key = '8c880999466a5f1670e1e87b2b4c70f1' made by require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wp_session_start, WP_Session::get_instance, WP_Session->__construct, WP_Session->read_data, WP_Session_Utils::get_session
       [15-Dec-2017 02:55:56 UTC] WordPress database error Table 'dnvxwyxfcy.wp_sm_sessions' doesn't exist for query SELECT * FROM wp_sm_sessions WHERE session_key = '8c880999466a5f1670e1e87b2b4c70f1' made by require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wp_session_start, WP_Session::get_instance, WP_Session->__construct, WP_Session->read_data, WP_Session_Utils::get_session
       [15-Dec-2017 02:55:58 UTC] WordPress database error Table 'wp_sm_sessions' already exists for query CREATE TABLE wp_sm_sessions (
                         session_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
                         session_key char(32) NOT NULL,
                         session_value LONGTEXT NOT NULL,
                         session_expiry BIGINT(20) UNSIGNED NOT NULL,
                         PRIMARY KEY  (session_key),
                         UNIQUE KEY session_id (session_id)
                       ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci made by do_action('admin_init'), WP_Hook->do_action, WP_Hook->apply_filters, create_sm_sessions_table, dbDelta
       ```
   

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Andrew Schultz](https://wordpress.org/support/users/tabboy/)
 * (@tabboy)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9787347)
 * It means that you don’t have permissions to create new tables. Add this line 
   to your wp-config.php file
 * `define( 'WP_SESSION_USE_OPTIONS', true );`
 * This is documented here
 * [https://github.com/ericmann/wp-session-manager](https://github.com/ericmann/wp-session-manager)
 *  Plugin Author [Eric Mann](https://wordpress.org/support/users/ericmann/)
 * (@ericmann)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9874678)
 * The database creation routine wasn’t wired correctly to run <i>before</i> session
   initialization as of v2.0.1. That specific bug was fixed in v2.0.2. This should
   be resolved now with either that or the latest 3.X versions.
 * Alternatively, Andrew’s suggestion to <i>force</i> options usage will skip working
   with a custom database table entirely. Either way, this should be resolved.
 * Please advise if that’s not the case.
 *  Thread Starter [therealgilles](https://wordpress.org/support/users/chamois_blanc/)
 * (@chamois_blanc)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9875416)
 * Hi Eric,
 * I have updated to v3.* and it seems to work fine. Note that I had to remove ‘
   define(WP_SESSION_USE_OPTIONS, true)’ from wp-config.php to things to work. That
   should maybe be mentioned somewhere in the documentation.
 *  Thread Starter [therealgilles](https://wordpress.org/support/users/chamois_blanc/)
 * (@chamois_blanc)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9875532)
 * It looks like the code to start a session should be conditioned on $_SESSION 
   not being already set, something like this:
 *     ```
       function my_session_start() {
         if (!isset($_SESSION)) {
           session_start();
         }
       }
   
       // Start up session management, if we're not in the CLI
       if (!defined('WP_CLI') || false === WP_CLI) {
           add_action('plugins_loaded', 'my_session_start', 10, 0);
       }
       ```
   
    -  This reply was modified 8 years, 4 months ago by [therealgilles](https://wordpress.org/support/users/chamois_blanc/).
 *  Plugin Author [Eric Mann](https://wordpress.org/support/users/ericmann/)
 * (@ericmann)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9875722)
 * The `session_start()` call will either start a new session or resume an existing
   one. Without that call, `$_SESSION` won’t be populated at all. See [http://php.net/manual/en/function.session-start.php](http://php.net/manual/en/function.session-start.php)
   for reference.
 *  Thread Starter [therealgilles](https://wordpress.org/support/users/chamois_blanc/)
 * (@chamois_blanc)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9875780)
 * I am getting a PHP notice because session_start() is being called when the session
   is already active. It is possible the session was started by some other plugin.
   That is why I am advocating to check whether the session was already started 
   before calling session_start().
 *  Plugin Author [Eric Mann](https://wordpress.org/support/users/ericmann/)
 * (@ericmann)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9880184)
 * I’m super curious what other code is calling `session_start()`, but that’s beside
   the point.
 * I added some more defensive coding in v3.0.3 (just released) that checks to see
   if the session is active before calling `session_start()`. If it’s already been
   started by some other code, then I won’t run a duplicate call.
 *  Thread Starter [therealgilles](https://wordpress.org/support/users/chamois_blanc/)
 * (@chamois_blanc)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9880399)
 * Here are some answers for you:
 *     ```
       			session_start();
       wp-content/plugins/woo-order-export-lite/classes/core/class-wc-order-export-engine.php
             session_start();
       wp-content/plugins/upme/modules/social/lib/facebook/facebook.php
       		session_start();
       wp-content/plugins/upme/modules/social/class-upme-facebook-connect.php
       		@session_start();
       wp-content/plugins/upme/modules/social/class-upme-linkedin-connect.php
               @session_start();
       wp-content/plugins/upme/modules/social/class-upme-google-connect.php
       		@session_start();		
       wp-content/plugins/upme/modules/social/class-upme-twitter-connect.php
                   session_start();
                       session_start();
       wp-content/plugins/updraftplus/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php
       ```
   
 * Thank you for making the change!
    -  This reply was modified 8 years, 4 months ago by [therealgilles](https://wordpress.org/support/users/chamois_blanc/).

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘WP Session creates database error’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-session-manager_272e38.svg)
 * [WP Session Manager](https://wordpress.org/plugins/wp-session-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-session-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-session-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-session-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-session-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-session-manager/reviews/)

## Tags

 * [database errors](https://wordpress.org/support/topic-tag/database-errors/)

 * 8 replies
 * 3 participants
 * Last reply from: [therealgilles](https://wordpress.org/support/users/chamois_blanc/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/wp-session-creates-database-error/#post-9880399)
 * Status: resolved