1

Estoy intentando guardar en una tabla utilizando $wpdb->insert, mi código es este:

$wpdb->insert('ordenes',
                array(
                      'user_id'=>11,
                      'seller_id'=>22,
                      'site_id'=>'USA',                             
                      'id_orden'=>333,
                      'items_id'=>444,
                      'titulo'=>'Prueba',
                      'cantidad'=>1,
                      'currency_id'=>'USD',
                      'precio'=>10,
                      'net_received_amount'=>8,
                      'date_created'=>'20-3-2019',
                      'date_closed'=>'20-3-2019',
                      'last_updated'=>'20-3-2019',
                      'expiration_date'=>'20-3-2019',                                                       
                      'order_status'=>'paid',
                      'total_amount'=>10,
                      'total_amount_with_shipping'=>10,
                      'paid_amount'=>10,                
                    ));

Para mi sorpresa se guarda 0 en site_id. Agrego:

$wpdb->show_errors();
$wpdb->print_error();

Y me devuelve esto:

Error en la base de datos de WordPress: []
INSERT INTO `ordenes` (`user_id`, `seller_id`, `site_id`, `id_orden`, 
`items_id`, `titulo`, `cantidad`, `currency_id`, `precio`, 
`net_received_amount`, `date_created`, `date_closed`, `last_updated`, 
`expiration_date`, `order_status`, `total_amount`, 
`total_amount_with_shipping`, `paid_amount`) VALUES (11, '22', 0, '333', 
'444', 'Prueba', '1', 'USD', '10', '8', '20-3-2019', '20-3-2019', '20-3-2019', 
'20-3-2019', 'paid', '10', '10', '10')

El único campo que me guarda mal es site_id. En la tabla es un varchar de 3, igual que currency_id.

Lo cursioso es que lo guarda perfectamente cuando hago:

$wpdb->get_results("INSERT into ordenes (user_id, seller_id, site_id, id_orden, items_id, titulo, cantidad, currency_id, precio, net_received_amount, date_created, date_closed, last_updated, expiration_date, order_status, total_amount, total_amount_with_shipping, paid_amount) values ('1', '22', 'USA', '3', '4', 'Prueba', '1', 'USD', '10', '10', '20-3-2019', '20-3-2019', '20-3-2019', '20-3-2019', 'paid', '10', '10', '10')");

Al hacer SHOW CREATE TABLE ordenes me devuelve:

CREATE TABLE `ordenes` (
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `user_id` bigint(20) NOT NULL,
 `seller_id` int(11) NOT NULL,
 `site_id` varchar(3) NOT NULL,
 `id_orden` bigint(20) NOT NULL,
 `items_id` varchar(15) NOT NULL,
 `titulo` varchar(60) NOT NULL,
 `cantidad` int(2) NOT NULL,
 `currency_id` varchar(3) NOT NULL,
 `precio` float(10,2) NOT NULL,
 `net_received_amount` float(10,2) DEFAULT NULL,
 `date_created` datetime NOT NULL,
 `date_closed` datetime NOT NULL,
 `last_updated` datetime NOT NULL,
 `expiration_date` datetime NOT NULL,
 `order_rating` varchar(10) NOT NULL,
 `order_rating_message` text DEFAULT NULL,
 `order_status` varchar(18) NOT NULL,
 `total_amount` float(10,2) NOT NULL,
 `total_amount_with_shipping` float(10,2) NOT NULL,
 `paid_amount` float(10,2) NOT NULL,
 `orden_md5` char(32) DEFAULT NULL,
 `notificado` varchar(1) DEFAULT NULL,
 `entregado` datetime DEFAULT NULL,
 `regalo_enviado` varchar(1) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=latin1

¿Como puedo solucionar este error?. Gracias!

12
  • 1
    Puede que sea de un tamaño menor, ¿sería posible que nos muestres el resultado de un SHOW CREATE TABLE ordenes;?
    – A. Cedano
    el 31 mar. 2019 a las 16:53
  • Cralo que si Cedano!, ahi lo agregue a la pregunta. Gracias!
    – Patricio
    el 1 abr. 2019 a las 2:42
  • 1
    ¿El INSERT que le mandas es exactamente el que presentas al inicio de la pregunta (usando valores directamente) o bien estás usando variables para setear los valores?¿Si intentas el INSERT directamente en el manejador de BD ocurre lo mismo, te pone ese campo en 0?
    – A. Cedano
    el 1 abr. 2019 a las 10:22
  • 1
    Lo probe con valores directamente, exactamente como esta en la pregunta e inserta 0
    – Patricio
    el 1 abr. 2019 a las 13:51
  • 1
    Lo único que se me ocurre es que tengas un TRIGGER que cambie el valor a 0. ¿Si intentas otro valor, como por ejemplo AAA también lo cambia por 0?
    – A. Cedano
    el 1 abr. 2019 a las 13:53

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.