WARNING WordPress.DB.DirectDatabaseQuery.DirectQuery Use of a direct database
-
This is my code my problem is when i check this code in wordpress plugin checker then show me the error
1. WARNING WordPress.DB.DirectDatabaseQuery.DirectQuery Use of a direct database call is discouraged.
2. WARNING WordPress.DB.DirectDatabaseQuery.NoCaching Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
How can i solved this problem ?
<?php
/********************************
* This file is for creating a database table for Leaflet.js map
****/
// Create database tables
function ikr_js_db_connection() {
global $wpdb;
// Table prefixes
$table_name_1 = $wpdb->prefix . 'ikr_leaflet_js_db';
$table_name_2 = $wpdb->prefix . 'ikr_default_setting';
$charset_collate = $wpdb->get_charset_collate();
// Create table 1 if it doesn't exist
// changed from General to Database
$table_exists_1 = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name_1 ) );
if ( $table_exists_1 != $table_name_1 ) {
$sql = "CREATE TABLE $table_name_1 (
id INT(10) NOT NULL AUTO_INCREMENT,
lat VARCHAR(100) NOT NULL,
lng VARCHAR(100) NOT NULL,
address VARCHAR(100) NOT NULL,
phone VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL,
urls VARCHAR(1000) NOT NULL,
marker_id VARCHAR(100) NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
// Insert default data using prepared statements
$wpdb->insert(
$table_name_1,
array(
'lat' => 23.8536047088421,
'lng' => 89.24606323242189,
'address' => '2',
'phone' => '100',
'email' => '300',
'urls' => 'https://hamjaiu.com',
'marker_id' => '88759345',
)
);
}
// Create table 2 if it doesn't exist
$table_exists_1 = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name_2 ) );
if ( $table_exists_1 != $table_name_2 ) {
$sql = "CREATE TABLE $table_name_2 (
id INT(10) NOT NULL AUTO_INCREMENT,
Latitude FLOAT NOT NULL DEFAULT 23.8536047088421,
Longitude FLOAT NOT NULL DEFAULT 89.24606323242189,
zoom FLOAT NOT NULL DEFAULT 12,
width FLOAT NOT NULL DEFAULT 50,
height FLOAT NOT NULL DEFAULT 50,
zoom_option VARCHAR(100) DEFAULT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
// Insert default data using prepared statements
$wpdb->insert(
$table_name_2,
array(
'Latitude' => 23.8536047088421,
'Longitude' => 89.24606323242189,
'zoom' => 2,
'width' => 100,
'height' => 300,
'zoom_option' => 'auto_zoom',
)
);
}
}
// Call the function to create/update tables
ikr_js_db_connection();
?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.