connect to another db and update a row in codeigniter - php

I am trying to update the already existing username field where id=1 , from admin#something.com to the string in $username but the default database is being updated , i want to connect to the newly created db and update the username field where id=1 in pr_users table but unable to connect to the newly created db and update the field.
I am calling a model to update the table i.e using $data['applicant_rows'] = $this->mod_common->add_new_user($email,$userid,$username); somehow the statements after foreach($sqls as $statement) is not working, Please help
below is my controller code:
Controller: login.php
public function save_userinput()
{
//code goes here
// for example: getting the post values of the form:
$form_data = $this->input->post();
// or just the username:
$username = $this->input->post("username");
$email = $this->input->post("email");
$userid = 1;
$data['applicant_rows'] = $this->mod_common->update_table_with_user_for_the_first_time($email,$userid,$username);
//$data['workspace'] = $this->mod_common->update_admin($email);
// $this->admin_list->manage_package();
$this->load->dbforge();
if ($this->dbforge->create_database($username))
{
try{
$current_database = $username;
$this->db->database = $current_database;
$data['applicant_rows'] = $this->mod_common->add_new_user($email,$userid,$username);
$this->db->close();
$config['hostname'] = "localhost";
$config['username'] = "root";
$config['password'] = "";
$config['database'] = $current_database;
$config['dbdriver'] = "mysql";
$config['dbprefix'] = $username;
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'home_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'login_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'other_bg' => array(
'type' =>'VARCHAR',
'constraint' => '200',
),
'uploaded_on' => array(
'type' => 'DATE',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_backgrounds', TRUE);
$fields = array(
'id' => array(
'type' => 'BIGINT',
'constraint' => 15,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'username' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => 'admin#ju.com',
),
'userpass' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => '65e1b655a6d6f4cbed20554d3b52521a743afdc0',
),
'email' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => 'admin#team.com',
),
'departmentid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '1',
),
'userroleid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '4',
),
'managerid' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => '10',
),
'userlevel' => array(
'type' => 'INT',
'constraint' => 11,
),
'branchid' => array(
'type' => 'INT',
'constraint' => 11,
'default' => '2',
),
'is_global' => array(
'type' => 'TINYINT',
'constraint' => 4,
'default' => '0',
),
'registrationtime' => array(
'type' => 'INT',
'constraint' => 10,
),
'timemodified' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'modifierid' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'status' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'deleted' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'temppass' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'temppassvalidtill' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastlogin' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'lastrefresh' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastloginip' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'if_online' => array(
'type' => 'INT',
'constraint' => 11,
),
'pfield' => array(
'type' => 'VARCHAR',
'constraint' => 255,
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_users', TRUE);
$sql = file_get_contents("assets/zipbizzlatestdb.sql");
/*
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements...
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements.
This small script splits the statements allowing you to run them all in one go.*/
$sqls = explode(';', $sql);
array_pop($sqls);
foreach($sqls as $statement){
$statment = $statement . ";";
$this->db->query($statement);
}
$this->loadanothercontroller();
}
catch(Exception $e){
echo "This name already exists in our database , Please choose another company name";
die;
}
}
// then do whatever you want with it :)
}
Model: mod_common.php
function add_new_user($email,$password,$username)
{
/* $sqls="INSERT INTO pr_users (username,userpass,email,departmentid,userroleid,managerid,userlevel,branchid,is_global,registrationtime,timemodified,modifierid,status,deleted,temppass,temppassvalidtill,lastlogin,lastrefresh,lastloginip,if_online,pfield) values ('$email','65e1b655a6d6f4cbed20554d3b52521a743afdc0','$email','1','4','10','4','2','0','0','1491557947','1','1','0','','0','1492084067','1492084083','1','0','unfold983$')";
$query=$this->db->query($sqls);*/
$defaultDB = $this->load->database('default', TRUE);
$id=1;
$col_name = 'username';
$sql="UPDATE pr_users
SET `".$col_name."` = '".addslashes($email)."'
WHERE `id` = '".$id."'";
$query=$this->db->query($sql);
if ($this->db->affected_rows() > 0) {
echo "Success";
# return TRUE;
}
else {
echo "failed";
# return FALSE;
}
}
pr_users table

Related

Insert query using dbForge is not inserting default values

I am trying to insert default values into a newly created table, however the table is created with no values. How can I insert values using dbForge after creating the table?
My Controller code is as follows:
$fields = array('id' =>
array('type' => 'INT','constraint' => 11,
'unsigned' => TRUE,'auto_increment' => TRUE),
'home_bg' => array('type' => 'VARCHAR','constraint' => '200',),
'login_bg' => array('type' => 'VARCHAR','constraint' => '200',),
'other_bg' => array('type' =>'VARCHAR','constraint' => '200',),
'uploaded_on' => array('type' => 'DATE',),);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_backgrounds', TRUE);
Try out this
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'home_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'other_bg' => array(
'type' =>'VARCHAR',
'constraint' => '200',
),
'uploaded_on' => array(
'type' => 'DATE'
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('ipn_log', TRUE);

Not able to call another controller method in codeigniter

I am creating a new database as part of the setup for each of my tenants, db is created successfully but is taking a lot of time , approx 5 min, on the other hand i am not able to call another controller method i.e admin_list controller and manage_package method inside it. This is my controller code:
<?php
class login extends CI_Controller
{
var $data;
function __construct() {
parent::__construct();
$this->load->helper('cookie');
require_once(APPPATH.'controllers/admin_list.php');
$is_admin_logged_in = $this->admin_init_elements->admin_logged_in_status();
global $USER;
if($is_admin_logged_in == TRUE){
redirect('home');
//;
}
//populate viewfor header / footer elements
$this->admin_init_elements->init_elements('N');
$this->load->model('mod_login');
}
public function save_userinput()
{
//code goes here
// for example: getting the post values of the form:
$form_data = $this->input->post();
// or just the username:
$username = $this->input->post("username");
echo $username;
// $this->admin_list->manage_package();
$this->load->dbforge();
if ($this->dbforge->create_database($username))
{
try{
$current_database = $username;
$this->db->database = $current_database;
$this->db->close();
$config['hostname'] = "localhost";
$config['username'] = "root";
$config['password'] = "";
$config['database'] = $current_database;
$config['dbdriver'] = "mysql";
$config['dbprefix'] = $username;
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'home_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'login_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'other_bg' => array(
'type' =>'VARCHAR',
'constraint' => '200',
),
'uploaded_on' => array(
'type' => 'DATE',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_backgrounds', TRUE);
$fields = array(
'id' => array(
'type' => 'BIGINT',
'constraint' => 15,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'username' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => 'admin#fold.com',
),
'userpass' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => '65e1b655a6d6f4cbed20554d3b52521a743afdc0',
),
'email' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => 'admin#fold.com',
),
'departmentid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '1',
),
'userroleid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '4',
),
'managerid' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => '10',
),
'userlevel' => array(
'type' => 'INT',
'constraint' => 11,
),
'branchid' => array(
'type' => 'INT',
'constraint' => 11,
'default' => '2',
),
'is_global' => array(
'type' => 'TINYINT',
'constraint' => 4,
'default' => '0',
),
'registrationtime' => array(
'type' => 'INT',
'constraint' => 10,
),
'timemodified' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'modifierid' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'status' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'deleted' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'temppass' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'temppassvalidtill' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastlogin' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'lastrefresh' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastloginip' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'if_online' => array(
'type' => 'INT',
'constraint' => 11,
),
'pfield' => array(
'type' => 'VARCHAR',
'constraint' => 255,
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_users', TRUE);
$sql = file_get_contents("assets/bizzlatestdb.sql");
/*
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements...
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements.
This small script splits the statements allowing you to run them all in one go.
*/
$sqls = explode(';', $sql);
array_pop($sqls);
foreach($sqls as $statement){
$statment = $statement . ";";
$this->db->query($statement);
}
}
catch(Exception $e){
echo "This name already exists in our database , Please choose another company name";
die;
}
$this->admin_list->manage_package();
}
// then do whatever you want with it :)
}
function index(){
$this->load->view('login', $this->data);
}
}
?>
You can load controller as library in Codeigniter2. But I don't think it is possible in Codeigniter3.
Load Controller as Library :
$this->load->library('../controllers/controller_name');
# Calling Methdod
$this->controller_name->method_name();

Split Mailalerts module recipients in prestashop

I need a specific list of recipients to receive stocks alerts only and another list of recipients to receive only the new order alert.
What is the best way to do it?
Thank you
Here is how I would deal with this question:
Create the override file /override/modules/mailalerts/mailalerts.php with this code:
<?php
class MailAlertsOverride extends MailAlerts
{
protected $merchant_mails_stock;
protected function init()
{
parent::init();
$this->merchant_mails_stock = str_replace(',', self::__MA_MAIL_DELIMITOR__, (string)Configuration::get('MA_MERCHANT_MAILS_STOCK'));
}
public function install($delete_params = true)
{
if (! parent::install($delete_params))
return false;
if ($delete_params)
{
Configuration::updateValue('MA_MERCHANT_MAILS_STOCK', Configuration::get('PS_SHOP_EMAIL'));
}
return true;
}
public function uninstall($delete_params = true)
{
if ($delete_params)
{
Configuration::deleteByName('MA_MERCHANT_MAILS_STOCK');
}
return parent::uninstall();
}
protected function postProcess()
{
$errors = array();
if (Tools::isSubmit('submitMAMerchant'))
{
$emails = (string)Tools::getValue('MA_MERCHANT_MAILS_STOCK');
if (!$emails || empty($emails))
$errors[] = $this->l('Please type one (or more) e-mail address');
else
{
$emails = str_replace(',', self::__MA_MAIL_DELIMITOR__, $emails);
$emails = explode(self::__MA_MAIL_DELIMITOR__, $emails);
foreach ($emails as $k => $email)
{
$email = trim($email);
if (!empty($email) && !Validate::isEmail($email))
{
$errors[] = $this->l('Invalid e-mail:').' '.Tools::safeOutput($email);
break;
}
elseif (!empty($email) && count($email) > 0)
$emails[$k] = $email;
else
unset($emails[$k]);
}
$emails = implode(self::__MA_MAIL_DELIMITOR__, $emails);
if (!Configuration::updateValue('MA_MERCHANT_MAILS_STOCK', (string)$emails))
$errors[] = $this->l('Cannot update settings');
}
}
if (count($errors) > 0)
{
$this->html .= $this->displayError(implode('<br />', $errors));
return $this->init();
}
parent::postProcess();
}
public function hookActionUpdateQuantity($params)
{
$this->merchant_mails = $this->merchant_mails_stock;
parent::hookActionUpdateQuantity($params);
}
public function renderForm()
{
$fields_form_1 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Customer notifications'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Product availability'),
'name' => 'MA_CUSTOMER_QTY',
'desc' => $this->l('Gives the customer the option of receiving a notification when an out-of-stock product is available again.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Order edit'),
'name' => 'MA_ORDER_EDIT',
'desc' => $this->l('Send a notification to the customer when an order is edited.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitMailAlert',
)
),
);
$fields_form_2 = array(
'form' => array(
'legend' => array(
'title' => $this->l('Merchant notifications'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('New order'),
'name' => 'MA_MERCHANT_ORDER',
'desc' => $this->l('Receive a notification when an order is placed.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Out of stock'),
'name' => 'MA_MERCHANT_OOS',
'desc' => $this->l('Receive a notification if the available quantity of a product is below the following threshold.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Threshold'),
'name' => 'MA_LAST_QTIES',
'class' => 'fixed-width-xs',
'desc' => $this->l('Quantity for which a product is considered out of stock.'),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Coverage warning'),
'name' => 'MA_MERCHANT_COVERAGE',
'desc' => $this->l('Receive a notification when a product has insufficient coverage.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'text',
'label' => $this->l('Coverage'),
'name' => 'MA_PRODUCT_COVERAGE',
'class' => 'fixed-width-xs',
'desc' => $this->l('Stock coverage, in days. Also, the stock coverage of a given product will be calculated based on this number.'),
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Returns'),
'name' => 'MA_RETURN_SLIP',
'desc' => $this->l('Receive a notification when a customer requests a merchandise return.'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
),
array(
'type' => 'textarea',
'cols' => 36,
'rows' => 4,
'label' => $this->l('E-mail addresses'),
'name' => 'MA_MERCHANT_MAILS',
'desc' => $this->l('One e-mail address per line (e.g. bob#example.com).'),
),
array(
'type' => 'textarea',
'cols' => 36,
'rows' => 4,
'label' => $this->l('E-mail stock addresses'),
'name' => 'MA_MERCHANT_MAILS_STOCK',
'desc' => $this->l('One e-mail address per line (e.g. bob#example.com).'),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitMAMerchant',
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->module = $this;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitMailAlertConfiguration';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name
.'&tab_module='.$this->tab
.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form_1, $fields_form_2));
}
public function getConfigFieldsValues()
{
$config = parent::getConfigFieldsValues();
$config['MA_MERCHANT_MAILS_STOCK'] = Tools::getValue('MA_MERCHANT_MAILS_STOCK', Configuration::get('MA_MERCHANT_MAILS_STOCK'));
return $config;
}
}

How to run multiple migrate file in CodeIgniter at once?

I am creating a migrate and at first table it seems ok but when I created my second migration there's no error but the table is not created.
I named my 2 migration class like this:
001_inititial_schema.php
002_create_table_quotation_header.php
The first one contains this:
class Migration_Initial_Schema extends CI_Migration {
public function up() {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'int',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true
),
'project_name' => array(
'type' => 'varchar',
'constraint' => 100,
),
'description' => array(
'type' => 'text'
),
'date_created' => array(
'type' => 'datetime',
),
'date_updated' => array(
'type' => 'datetime',
),
'status' => array(
'type' => 'tinyint',
'default' => 1
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('flx_project');
}
public function down() {
$this->dbforge->drop_table('flx_project');
}
}
Then the second one:
class CreateTableQuotationHeader extends CI_Migration {
public function up() {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'int',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true
),
'project_id' => array(
'type' => 'int',
'constraint' => 11,
'unsigned' => true,
),
'receiver' => array(
'type' => 'varchar',
'constraint' => 100,
),
'address' => array(
'type' => 'text',
),
'attention' => array(
'type' => 'varchar',
'constraint' => 100
),
'reference_number' => array(
'type' => 'varchar',
'constraint' => 50
),
'date_issued' => array(
'type' => 'date'
)
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('flx_project_header');
}
public function down() {
$this->dbforge->drop_table('flx_project_header');
}
}
Then in my controller:
<?php
class Migrate extends CI_Controller {
public function __construct() {
parent::__construct(0);
$this->load->library('migration');
}
public function index() {
$this->load->helper('template');
if(!$this->migration->current()) {
show_error($this->migration->error_string());
} else {
$data['message'] = 'migrate success';
}
renderPage('common/migrate', $data);
}
}
?>
Ok I solved my problem what I did is I include both the migration in 1 file only. But I don't know if it is a proper way in runnning the migration that has a multiple tables.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Initial_Schema extends CI_Migration {
public function up() {
$this->dbforge->add_field(array(
'id' => array(
'type' => 'int',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true
),
'project_name' => array(
'type' => 'varchar',
'constraint' => 100,
),
'description' => array(
'type' => 'text'
),
'date_created' => array(
'type' => 'datetime',
),
'date_updated' => array(
'type' => 'datetime',
),
'status' => array(
'type' => 'tinyint',
'default' => 1
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('flx_project');
$this->dbforge->add_field(array(
'blog_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'blog_title' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'blog_description' => array(
'type' => 'TEXT',
'null' => TRUE,
),
));
$this->dbforge->add_key('blog_id', TRUE);
$this->dbforge->create_table('blog');
}
public function down() {
$this->dbforge->drop_table('flx_project');
$this->dbforge->drop_table('blog');
}
}
?>

drupal_write_record in drupal 6 returning false

When I run drupal_write_record, it always comes back false. I've debugged into the function and see that drupal_get_schema function, found inside drupal_write_record function, returns false. Further more, if I debug into drupal_get_schema function and look at
$schema = $cached->data;
My new table is not included in the $schema array. I've tried flushing the cache, reinstalling the module, and running update.php but nothing helps. In the event it helps, I've also included the .install file I wrote that adds the new table to the database:
<?php
// $Id: my_module.install,v 1.00.0.1 2012/10/21 00:23:32 Exp $
/**
* Implementation of hook_schema().
*/
function my_module_schema() {
$schema = array();
$schema['my_module_pending_inserts'] = array(
'fields' => array(
'id' => array(
'description' => 'primary key',
'type' => 'serial',
'size' => 'tiny',
'not null' => TRUE,
),
'json_array_data' => array(
'type' => 'text',
'not null' => TRUE,
),
'successfully_run' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'date_created' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'date_updated' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
)
),
'primary key' => array('id'),
);
return $schema;
}
function jira_reporting_install() {
// Create tables.
drupal_install_schema('my_module_pending_inserts');
}
function my_module_uninstall() {
// Remove tables.
drupal_uninstall_schema('my_module_pending_inserts');
// Delete variables
variable_del('my_module_variable1');
variable_del('my_module_variable2');
variable_del('my_module_variable3');
}
function my_module_update_2() {
$up = array();
$tbl = array(
'fields' => array(
'id' => array(
'type' => 'serial', 'not null' => TRUE
),
'json_array_data' => array(
'type' => 'varchar',
'length' => 250,
'not null' => True
),
'successfully_run' => array(
'type' => 'int'
),
'date_created' => array(
'type' => 'int'
),
'date_updated' => array(
'type' => 'int'
),
),
'primary key' => array('id'),
);
db_create_table(&$up, 'my_module_pending_inserts', $tbl);
return $up;
}
never mind, it was a typo in my _schema name

Categories