0

私はこれをしばらくの間機能させようとしてきました。私はただ困惑しています。これが元の MYSQL で、次に私が取り組んでいる PHP です。

マイSQL:

SET @COD_PAIS = 3;
SET @F_HASTACORTE = '2012-03-31 01:00:00';

SELECT mcarteras.DES_CARTERA_CC                 AS 'Short Name of Fund'
     , mcarterasflias.DES_CARTERAFLIA           AS 'I/C'
     , msociedades.DES_SOCIEDAD_CORTO           AS 'Fund Manager Company'
     , mcarteras_clases.DES_CARTERACLASE        AS 'Class'
     , mcarteras_clasesesp.DES_CARTERACLASE_ESP AS 'Special Class'
     , dr_rentmovil_carteras.POR_RENTCARTERA    AS 'TTR year-to-date %'
     , dficha_mes.POR_REMUNERA_COBRADA          AS 'Mgmt Fee Effectively Charged'
     , dficha_mes.POR_GASTOS_TOTALESC           AS 'Total Expenses %'
     , dficha_mes.VR_CARTERA_FCORTE             AS 'Fund Size'
     , dr_rentmovil_carteras.F_HASTACORTE             AS 'Date'
  FROM mcarteras
INNER
  JOIN mcarterasflias
    ON mcarterasflias.ID_CARTERAFLIA           = mcarteras.ID_CARTERAFLIA
INNER
  JOIN msociedades
    ON msociedades.ID_SOCIEDAD                 = mcarteras.ID_SOCIEDADADM
INNER
  JOIN mcarteras_clases
    ON mcarteras_clases.ID_CARTERACLASE        = mcarteras.ID_CARTERACLASE
INNER
  JOIN mcarteras_clasesesp
    ON mcarteras_clasesesp.ID_CARTERACLASE_ESP = mcarteras.ID_CARTERACLASE_ESP  
INNER
  JOIN dr_rentmovil_carteras
    ON dr_rentmovil_carteras.ID_CARTERA        = mcarteras.ID_CARTERA   
   AND dr_rentmovil_carteras.COD_PAIS                                       = @COD_PAIS
   AND dr_rentmovil_carteras.F_HASTACORTE                                =@F_HASTACORTE
   AND dr_rentmovil_carteras.ID_FORMATO = 1
   AND dr_rentmovil_carteras. ID_COLUMNA = 5
INNER
  JOIN dficha_mes
    ON dficha_mes.ID_CARTERA                   = mcarteras.ID_CARTERA   
   AND dficha_mes.COD_PAIS                                                  = @COD_PAIS
   AND dficha_mes.F_CORTE                                              = @F_HASTACORTE 

 WHERE mcarteras.COD_PAIS                                                   = @COD_PAIS
   AND mcarteras.ID_CARTERATIPO = 4
   AND mcarteras.ID_CARTERAFLIA IN ( 3,4 )
   AND mcarteras.IND_PUBLICACION = 1
   AND mcarteras.COD_ESTADO= 1

PHP:
<?php
$con = mysql_connect("localhost","root","");
 if (!$con)
   {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("bdcarterascv2", $con);
$COD_PAIS = '3';
$F_HASTACORTE = '2012-03-31 01:00:00';

$result = mysql_query("SELECT DES_CARTERA_CC               AS 'Short Name of Fund' 
     , mcarterasflias.DES_CARTERAFLIA           AS 'I/C'
     , msociedades.DES_SOCIEDAD_CORTO           AS 'Fund Manager Company'
     , mcarteras_clases.DES_CARTERACLASE        AS 'Class'
     , mcarteras_clasesesp.DES_CARTERACLASE_ESP AS 'Special Class'
     , dr_rentmovil_carteras.POR_RENTCARTERA    AS 'TTR year-to-date %'
     , dficha_mes.POR_REMUNERA_COBRADA          AS 'Mgmt Fee Effectively Charged'
     , dficha_mes.POR_GASTOS_TOTALESC           AS 'Total Expenses %'
     , dficha_mes.VR_CARTERA_FCORTE             AS 'Fund Size'
     ,dr_rentmovil_carteras.F_HASTACORTE        AS'Date'
  FROM mcarteras 
INNER
  JOIN mcarterasflias
    ON mcarterasflias.ID_CARTERAFLIA           = mcarteras.ID_CARTERAFLIA
INNER
  JOIN msociedades
    ON msociedades.ID_SOCIEDAD                 = mcarteras.ID_SOCIEDADADM
INNER
  JOIN mcarteras_clases
    ON mcarteras_clases.ID_CARTERACLASE        = mcarteras.ID_CARTERACLASE
INNER
  JOIN mcarteras_clasesesp
    ON mcarteras_clasesesp.ID_CARTERACLASE_ESP = mcarteras.ID_CARTERACLASE_ESP  
INNER
  JOIN dr_rentmovil_carteras
    ON dr_rentmovil_carteras.ID_CARTERA        = mcarteras.ID_CARTERA   
  AND dr_rentmovil_carteras.COD_PAIS                                       =  $COD_PAIS
   AND dr_rentmovil_carteras.F_HASTACORTE                          =      $F_HASTACORTE
   AND dr_rentmovil_carteras.ID_FORMATO = 1
   AND dr_rentmovil_carteras. ID_COLUMNA = 5
INNER
  JOIN dficha_mes
    ON dficha_mes.ID_CARTERA                   = mcarteras.ID_CARTERA   
   AND dficha_mes.COD_PAIS                                            =      $COD_PAIS
   AND dficha_mes.F_CORTE                                             =  $F_HASTACORTE 

 WHERE mcarteras.COD_PAIS                                                =  $COD_PAIS
   AND mcarteras.ID_CARTERATIPO = 4
   AND mcarteras.ID_CARTERAFLIA IN ( 3,4 )
   AND mcarteras.IND_PUBLICACION = 1
   AND mcarteras.COD_ESTADO= 1
")
or die(mysql_error());

// HTML ... Aliases from Mysql
echo "<table border='1'>
<tr>
<th>Short Name of Fund</th>
<th>I/C</th>
<th>Fund Manager Company</th>
<th>Class</th>
<th>Special Class</th>
<th>TTR year-to-date %</th>
<th>Mgmt Fee Effectively Charged</th>
<th>Total Expenses %</th>
<th>Fund Size</th>
<th>Date</th>
</tr>";

//<tr> specifies table row. for each <td> (table data) will specify a new column.  The     $row specifies the mysql column name (in this case using an alias)
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Short Name of Fund'] . "</td>";
 echo "<td>" . $row['I/C'] . "</td>";
  echo "<td>" . $row['Fund Manager Company'] . "</td>";
  echo "<td>" . $row['Class'] . "</td>";
  echo "<td>" . $row['Special Class'] . "</td>";
  echo "<td>" . $row['TTR year-to-date %'] . "</td>";
  echo "<td>" . $row['Mgmt Fee Effectively Charged'] . "</td>";
  echo "<td>" . $row['Total Expenses %'] . "</td>";
  echo "<td>" . $row['Fund Size'] . "</td>";
   echo "<td>" . $row['Date'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

現在のエラーは次のとおりです。SQL 構文にエラーがあります。28 行目の '01:00:00 AND dr_rentmovil_carteras.ID_FORMATO = 1 AND dr_rentmovil_carte' 付近で使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。

どんな助けでも大歓迎です。

4

3 に答える 3

3

日時文字列を引用符で囲む必要があります。

='$F_HASTACORTE'

2012-03-31 01:00:00それ以外の場合は、日時ではなく数値として評価されます。

于 2012-08-23T18:37:30.337 に答える
1

あなたはおそらくあなたの周りに引用符を入れたいと思うでしょう'$VARIABLES'. そうでない場合は、それらをエスケープします。

于 2012-08-23T18:37:16.953 に答える
0

試す:

AND dr_rentmovil_carteras.F_HASTACORTE                          =      '$F_HASTACORTE'

変数が整数でない場合は、それらをクォートする必要があります。これを行う必要がある場所が他にもいくつかあります。

また、mysql_* 関数の代わりに PDO を使用することも検討する必要があります。バインドされたパラメーターを使用すると、この種の問題の多くをうまく回避できます。

于 2012-08-23T18:37:20.493 に答える