> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/wordpress/dbdelta-sql-database-ok.md).

# dbDelta sql database (ok)

```
private function index_test_001() {
     global $wpdb;
     $table_name = $wpdb->prefix . 'dbdelta_test_001';
     $wpdb_collate = $wpdb->collate;
     $sql =
         "CREATE TABLE {$table_name} (
         id mediumint(8) unsigned NOT NULL auto_increment ,
         first varchar(255) NULL,
         PRIMARY KEY  (id),
         KEY first (first)
         )
         COLLATE {$wpdb_collate}";
 
     require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     dbDelta( $sql );
 }
```

Hoặc

```
public function lionel_content_db_install () {
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate ();
    $this->lionel_content_set_wpdb_tables ();
    require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
    $sql = "CREATE TABLE IF NOT EXISTS $wpdb->lionel_content_logs (
        `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
        `post_id` int(11) NOT NULL,
        `action` enum('publish','update','repost','bulk_publish', 'share', 'add_queue') DEFAULT NULL,
        `request_sent` datetime NOT NULL,
        `profile_id` varchar(191) NOT NULL,
        `profile_name` varchar(191) NOT NULL DEFAULT '',
        `result` enum('success','test','pending','warning','error') NOT NULL DEFAULT 'success',
        `result_message` text,
        `status_text` text,
        `status_image` text,
        `status_link` text,
        `status_created_at` datetime DEFAULT NULL,
        `status_due_at` datetime DEFAULT NULL,
        `lionel_posting_schedule` text,
        PRIMARY KEY (`id`),
        KEY `post_id` (`post_id`),
        KEY `action` (`action`),
        KEY `result` (`result`),
        KEY `profile_id` (`profile_id`)
      ) {$charset_collate};";
    dbDelta ($sql);
      $sqlCate = "CREATE TABLE IF NOT EXISTS $wpdb->lionel_categories (
        `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
        `name` varchar(191) NOT NULL DEFAULT '',
        `description` text,
        `random_availability` int(1) NOT NULL DEFAULT 1,
        `status` int(1) NOT NULL DEFAULT 1,
        `is_default` int(1) DEFAULT NULL,
        `created_at` datetime DEFAULT NULL,
        `updated_at` datetime DEFAULT NULL,
        PRIMARY KEY (`id`)
      ) {$charset_collate};";
    dbDelta ( $sqlCate );
    $categories = $wpdb->get_results ( "SELECT * FROM {$wpdb->lionel_categories}" );
    if(empty((array)$categories)) {
      $dateNow = date('Y-m-d H:i:s');
      $insertSql = "INSERT INTO {$wpdb->lionel_categories}(name, description, random_availability, status, is_default, created_at, updated_at) VALUES ('Your evergreen content', 'Use this category to promote your own content - share any blog posts or pages you publish.', 1, 1, 1, '$dateNow', null), ('Promotional', 'Use this category to promote your services/products. Make sure to include Calls To Actions (CTAs) like \"Book a call with us\" or \"start a trial account\".', 1, 1, 0, '$dateNow', null), ('Quotes, Questions, and Fun', 'Use this category to generate engagement on your socials. Share inspirational or fun quotes, from your niche or create open questions for your audience.', 1, 1, 0, '$dateNow', null)";
      dbDelta($insertSql);
    }
  }
```

{% file src="/files/-MchwB\_igSlX9-1hmqxR" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/wordpress/dbdelta-sql-database-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
