Welcome Guest, Not a member yet? Register   Sign In
MySQL query fail in CI and PHP but not with MySQL client
#1

[eluser]Unknown[/eluser]
Hello,

I'm baffled by this one.

I have this long MySQL query that fails in CI and with the mysql_* PHP functions, but works perfectly with the MySQL client on the command line, or with Navicat.

Here's the query and my code in CI. If I run this query in CI, or in "classic" PHP, I get an Error Number: 1064. But if I copy the query shown in the web page to the MySQL client, or Navicat, everything is fine. What's going on? It seems that its a more PHP problem than a CI problem. TIA.

Cheers
-Emmanuel


function obtient_id($numero_cohorte, $annee_programme) {

$sql = <<<EOF
DROP TEMPORARY TABLE IF EXISTS temptable1;
DROP TEMPORARY TABLE IF EXISTS temptable2;
CREATE TEMPORARY TABLE temptable1 (id int);
INSERT INTO temptable1
SELECT usagers_admin.id FROM usagers_admin
WHERE usagers_admin.nom='statut_annee_programme'
AND usagers_admin.valeur='$annee_programme';
CREATE TEMPORARY TABLE temptable2 (id int);
INSERT into temptable2
SELECT usagers_admin.id from usagers_admin
WHERE usagers_admin.nom='statut_cohorte_selection'
AND usagers_admin.valeur='$numero_cohorte';
SELECT temptable1.id from temptable1, temptable2
WHERE temptable1.id=temptable2.id;
EOF;

$requete_resultat = $this->db->query($sql);

if ( $requete_resultat->num_rows() > 0 ) {
$utilisateurs_id = array();
foreach ( $requete_resultat->result() as $rang ) {
$utilisateurs_id[] = $rang->id;
}
return $utilisateurs_id;
} else {
return FALSE;
}
}


Messages In This Thread
MySQL query fail in CI and PHP but not with MySQL client - by El Forum - 02-04-2009, 10:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB