Jump to content
php.lv forumi

Wordpress spraudnis neizveido tabulu pēc pieprasījuma


_PUIKA_

Recommended Posts

Labdien.

Vakarnakt saskāros ar problēmu, rakstot wordpress spraudni.

Ieskatam, re:

Galvenais index.php fails (galvene ar spraudņa informāciju šeit nav iekļauta)

Fails pieprasa funckciju failu..

// Asking for functions (constants, setups, etc.)
require_once( ABSPATH . "wp-content/plugins/sarsauto/includes/functions.php" );

Tālāk.. funkciju fails (definēju mapes un pieprasu pārbaudīt instalācijas failu)

tik tālu viss ok..

// Defining plugin's root directory's constant name
define( "dSARSAUTO", ABSPATH . "wp-content/plugins/sarsauto/" );
// Defining plugin's includes directory's constant name
define( "dINCLUDES", dSARSAUTO . "includes/" );
//
/* END OF CONSTANTS */


/* SETUPS */
//
// Asking for setup.php file and if exists create function
if( file_exists( dINCLUDES . "setup.php" ) ){
 // Require setup.php file
 include( dINCLUDES . "setup.php" );
 // On plugin activation ask for table setup function
 register_activation_hook( __FILE__, "sarsauto_table_setup" );
}else{
 echo "Error: file doesn't exists!";
}

 

Un te ir arī pats instalācijas fails:

// Setting up table version for later upgrades
global $sarsauto_version;
$sarsauto_table_version = "0.1.beta";

// Creating table
function sarsauto_table_setup() {
 global $wpdb;
 global $sarsauto_table_version;
 $table_name = $wpdb->prefix . "sarsauto";

 if( $wpdb->get_var( "show tables like '$table_name'" ) != $table_name ){
  $sql = "CREATE TABLE " . $table_name . " (
id int(11) NOT NULL AUTO_INCREMENT,
UNIQUE KEY id (id)
);";
 }


 // The dbDelta function examines the current table structure,
 // compares it to the desired table structure, and either adds
 // or modifies the table as necessary.
 require_once( ABSPATH . "wp-admin/includes/upgrade.php" );
 dbDelta( $sql );
 add_option( "sarsauto_table_version", $sarsauto_table_version );
}

 

Tātad, pie spraudņa palaišanas funkciju failā IF funkcija pārbauda vai instalācijas fails eksistē, un ja eksistē, tad notiek tā faila integrēšana un galvenā tabulu instalācijas funkcija tiek izsaukta, kura principā pārbauda vai tabula eksistē, un ja nē, tad laižam SQL query,

It kā visam vajadzētu iet, bet kad pārbaudu /phpmyadmin/ wordpress datubāzes tabulu sarakstu, nekādu izmaiņu (t.i. tabula 'sarsauto' neizveidojas).

Kāds zin kas par vainu?

Paldies jau iepriekš.

Ričards :)

 

p.s. atvainojos par angļu valodu komentāros (praktizēju).

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...