Problem in mysql stored procedure (Illegal mix of collations (utf8_unicode_ci, IMPLICIT) and (utf8_general_ci, IMPLICIT) for operation '=')

0

I have a stored procedure, which tries to validate that the user and the mail that is being entered does not exist in the database before creating the record (inserting them) in the database. The code I have is this:

CREATE DEFINER='root'@'localhost' PROCEDURE 'ups_crearEmpresa'(IN '_usuario' VARCHAR(16), IN '_nombre' VARCHAR(30), IN '_ap1' VARCHAR(30), IN '_email' VARCHAR(50), IN '_password' TEXT, IN '_ip' TEXT)
BEGIN
set @token =SHA(_email+now()+_nombre);
set @pass = _password;

#Se valida que el correo no exista actualmente en la tabla de usuarios para empresa
SET @validaremail = (select email from empresas_usuariosprincipales where email=_email) ;
#Se valida que el usuario de la empresa no exista en la tabla de usuarios para empresa
set @validarusuario = (select usuario from empresas_usuariosprincipales where usuario=_usuario) ;


IF (_usuario  = @validarusuario ) THEN
set @a = 2;
SELECT @a codigo, 'El nombre de usuario ya existe.' as mensaje;

ELSE IF (_email =  @validaremail) THEN
set @a = 3;
SELECT @a codigo, 'La cuenta de correo electrónico ya existe.' as mensaje;
ELSE
#Se insertan los datos en la tabla empresas para obtener el id de la empresa
INSERT INTO empresas (TOKEN, fecharegistro, id_paquete) values (@token, now(), 1);
set @idempresa = (SELECT MAX(id) FROM empresas);

#se insertan los datos en la tabla de usuarios para empresas
INSERT INTO empresas_usuariosprincipales  (id_empresa, usuario, password, email, nombre, apellido1, ip) 
values (@idempresa, _usuario, _password, _email, _nombre, _ap1, _ip);

#se crea registro que contiene los privilegios para la empresa con las características del plan gratuito.
INSERT INTO  empresas_privilegios(id_empresa, perfilpublico, vercvpostulados, publicarofertas, ofertasmensuales, ofertasconsumidas, usuariosadicionales, usuariosconsumidos, mascaracorreo, mailbox, topofertas)
values (@idempresa, 1, 1, 1, 10, 0, 0, 0, 0, 0, 0);

#se crea el registro de la tabla de configuraciones
INSERT INTO empresas_config (id_empresa) values (@idempresa);

set @a = 1;
SELECT @a codigo, 'La cuneta se creó con éxito.' as mensaje, @token token;

END IF;
END IF;
END

In localhost it works great for me but on the production server it throws me the following error that I can not repair :(

Illegal mix of collations (utf8_unicode_ci, IMPLICIT) and (utf8_general_ci, IMPLICIT) for operation '='

Do a testo and the problem is in the if, you are sending me that error when comparing the value of the variable that I receive with the value that I get from the query.

IF (**_usuario  = @validarusuario** ) THEN

In this link they say possible solutions: link

I've already updated my tables, one by one running this command, but it still does not work:

ALTER TABLE users CHARACTER SET utf8 COLLATE utf8_general_ci;

Thanks for your comments. A hug.

    
asked by Neftali Acosta 29.08.2018 в 04:35
source

1 answer

0

I already found the problem. For some reason, when exporting and importing the database to the production server the engine of the table had been changed. I had InnDB, I just changed it to MyISAM and it was resolved :) prnt.sc/ko2gls

THANKS FOR EVERYTHING!

    
answered by 30.08.2018 в 08:18