Realmente no he conseguido identificar si se trata de un error que tengo en PHP o en MySQL (apuesto por lo segundo).
Es tan sencillo y tan tonto como una serie de sentencias que se ejecutan sin problemas desde phpMyAdmin, pero que al ejecutarlas desde PHP dan error.
Las sentencias son:
Código PHP:
DROP TEMPORARY TABLE IF EXISTS tTemp;
CREATE TEMPORARY TABLE tTemp(
`t_telefonoC` varchar(9) ,
`t_nombreC` varchar(150) ,
`t_direccionC` varchar(500) ,
`t_poblacionC` varchar(100) ,
`t_postalC` smallint(8) UNSIGNED,
`t_email` varchar(200) );
INSERT INTO tTemp
(`t_telefonoC`,`t_nombreC`,`t_direccionC`,`t_poblacionC`,`t_postalC`,`t_email`)
VALUES
('915550011', 'Familia Perez Fernandez', 'C/ Pipas 7', 'Madrid', '', '[email protected]');
INSERT INTO clientes
(`telefonoC`,`nombreC`,`direccionC`,`poblacionC`,`postalC`,`email`)
SELECT tt.* FROM tTemp tt
LEFT JOIN clientes t ON t.telefonoC = tt.t_telefonoC
WHERE t.telefonoC IS NULL;
UPDATE clientes t
LEFT JOIN tTemp tt
ON t.telefonoC = tt.t_telefonoC
SET `nombreC` = tt.t_nombreC,
`direccionC` = tt.t_direccionC,
`poblacionC` = tt.t_poblacionC,
`postalC` = tt.t_postalC,
`email` = tt.t_email
WHERE tt.t_telefonoC IS NOT NULL;
DROP TEMPORARY TABLE tTemp;
Código PHP:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; CREATE TEMPORARY TABLE tTemp( `t_telefonoC` varchar(9) , `t_nombreC` varchar(1' at line 1
Código PHP:
$cSQL = "DROP TEMPORARY TABLE ... "; // En el original está completo
mysql_query($cSQL, $conn) or die(mysql_error());