[英]Php variables in SQL query
I have php file with sql query, where are the php variables: 我有带有sql查询的php文件,php变量在哪里:
<?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); 这是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! 谢谢!
include
directive is evaluating included file but in limited scope. include
指令正在评估包含文件,但范围有限。 When you're including file from inside a function, only variables local to this function are accesible for included file . 当您从函数内部包含文件时, 仅此函数本地的变量可用于include 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
. 在此之前,您只有一个局部变量,包括: $query_file
。
I would recommend manual importing of variables to local scope. 我建议手动将变量导入本地范围。 You can see some example here: https://stackoverflow.com/a/10144260/925196 您可以在此处看到一些示例: https : //stackoverflow.com/a/10144260/925196
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.