无法使用oracle查询使用数据库中的表填充PHP表(错误:尝试获取非对象的属性)

无法使用oracle查询使用数据库中的表填充PHP表(错误:尝试获取非对象的属性),php,sql,database,oracle,Php,Sql,Database,Oracle,我试图用查询填充一个表,但它给了我一个错误: 注意:试图在[LINENUMBER]行的[DIRECTORY]中获取非对象的属性 该行指向$curs的每个实例 以下是我如何调用数据库中的数据: $MyQuery = " //the query that is needed for the data to fill the table select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nomina

我试图用查询填充一个表,但它给了我一个错误:

注意:试图在[LINENUMBER]行的[DIRECTORY]中获取非对象的属性

该行指向$curs的每个实例

以下是我如何调用数据库中的数据:

$MyQuery = " //the query that is needed for the data to fill the table
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
            ";

$curs=$conn->Execute($MyQuery); //parsing the database with the query
因此,我尝试使用另一个表来检查是否是其他代码出错,或者只是sql查询

大概是这样的:

select ndate, dealer, location, price 
    from mydatabase.regionalsales
    where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
    and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')
网站运行正常,表格中完美地填写了查询结果

然后我开始怀疑是不是我的桌子出了问题。但是,我不知道我的桌子怎么了。所以我来到这里。这是我桌子上的一些东西,希望这能有所帮助:

这张桌子有问题吗?我已经检查了好几张表,它是有效的,但这张不行。请提供帮助,提前感谢。

oracle中的评论是-或/*…*/不是//,因此您的查询是错误的,请更改为

$MyQuery = "-- the query that is needed for the data to fill the table
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
";
或者更好,除非您将已执行查询的历史记录保存在某个位置,并希望该注释显示在该位置:

// the query that is needed for the data to fill the table
$MyQuery = "
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
";
插入这样的值不是很安全,这是一个很好的问题:

它适用于mysql,但oracle具有相同的功能,例如oracle中的oci_bind_by_name

注释是-或/*…*/不是//,因此您的查询是错误的,请更改为

$MyQuery = "-- the query that is needed for the data to fill the table
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
";
或者更好,除非您将已执行查询的历史记录保存在某个位置,并希望该注释显示在该位置:

// the query that is needed for the data to fill the table
$MyQuery = "
select ndate, code, channel, credit, countedstock, systemstock, discrepancy, nominal 
from mydatabase.stockdiscrepancy
where to_date(ndate,'YYYY-MM-DD') >= to_date('".$from."','YYYY-MM-DD') 
and to_date(ndate,'YYYY-MM-DD') <= to_date('".$to."','YYYY-MM-DD')   
";
插入这样的值不是很安全,这是一个很好的问题:


它是针对mysql的,但oracle具有相同的功能,例如oci_bind_by_name

在执行之前,您可以向我们显示$MyQuery的内容吗?是否直接在oracle上运行?在执行之前,能否向我们显示$MyQuery的内容?这是直接在oracle上运行的吗?没有人,当然我没有这样写评论,lol,我在这里写的时候写了这些评论,所以你可以放心地忽略这些评论。@soryuken好的,然后删除where子句,看看表是否有问题,如果这样做有效,那么您可能有格式不正确或非法的日期。顺便说一句。如果你总是使用yyyy mm dd格式,你不需要转换日期,即使是NULL也会以同样的方式处理。没有人,当然我没有这样写注释,我在这里写注释时写了这些注释,所以你可以安全地忽略注释。@soryuken ok,然后删除where子句,看看表是否有问题,如果这样做有效,那么您可能有格式不正确或非法的日期。顺便说一句,如果您总是使用yyyy-mm-dd格式,则不需要转换日期,即使NULL也会以相同的方式处理。