donglu5047 2013-08-13 14:37
浏览 47

SQL查询中的Php变量

I have php file with sql query, where are the php variables:

<?php
$request = "SELECT
sp.product_id AS $select_1,
sp.last_price AS $select_2,
sp.bu_key AS $select_3
  FROM $stamp.supplier_product sp 
  WHERE  sp.bu_key = '$country'
  AND sp.product_id IN ('$textarea_1') 
  AND to_timestamp('$startDate', 'yyyy-mm-dd HH24:mi:ss.FF3') > sp.available_from_date
  AND (sp.available_thru_date > to_timestamp('$endDate', 'yyyy-mm-dd HH24:mi:ss.FF3') OR sp.available_thru_date is NULL)
  AND sp.packaging_id = 'NO_PACKAGING'"; 
  ?>`

Also I have class with function, which call the content of the file:

class GetContent {     
private $directory;
private  $query_file;

public function __construct($directory, $query_file) 
{ 

$this->query_file = $query_file;    
$this->directory = $directory;
}      public function get_content($query_file)   
{   
     file_get_contents($query_file);
     $content = file_get_contents($query_file);
     echo nl2br( htmlspecialchars($content));  
} 
  public function include_file($query_file)   
{   include($query_file);
     var_dump($request);  
} }

and Call the class:

<?php
include('date_box.php');
$query_names = 'C:\\apache\\htdocs\\menue\\product\\queries';
$obj = new SelectOption($query_names);
$obj->get_diretory($query_names);
?>

My probles is: When I execute the query there are no variable, it can not to find them in my file. THis is the result of var_dump($request);

string(416) "SELECT sp.product_id AS , sp.last_price AS , sp.bu_key AS FROM
supplier_product sp WHERE sp.bu_key = '' AND sp.product_id IN ('') 
AND to_timestamp('', 'yyyy-mm-dd HH24:mi:ss.FF3') > sp.available_from_date 
AND (sp.available_thru_date > to_timestamp('', 'yyyy-mm-dd HH24:mi:ss.FF3') 
OR sp.available_thru_date is NULL) AND sp.packaging_id = 'NO_PACKAGING'"

What I have to do for GET my variables from text?

Thank you!

  • 写回答

1条回答 默认 最新

  • douqiao6015 2014-05-23 09:35
    关注

    include directive is evaluating included file but in limited scope. When you're including file from inside a function, only variables local to this function are accesible for included file. And as you see:

    public function include_file($query_file)   
    {   include($query_file);
        var_dump($request);  
    }
    

    You have only one local variable here before including: $query_file.

    I would recommend manual importing of variables to local scope. You can see some example here: https://stackoverflow.com/a/10144260/925196

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决