ODBC查询单独工作,在函数调用中失败

时间:2018-04-12 21:30:58

标签: php wordpress function odbc

require_once('/ip/****/wwws/include/connect.php');
require_once( __DIR__ . '/function_includes/events_home.php');
require_once( __DIR__ . '/function_includes/events_inner_shortcode.php');
$dbc文件中创建

connect.php

events_home.php效果很好。执行并返回$results

$query="SELECT * from events where( EventDate >='$today' and hide=1) order     by EventDate";
$result=odbc_exec($dbc,$query);
尝试查看已执行的events_inner_shortcode.php

时,

$result返回NULL

function innerEvents() {
$query="SELECT * from events where( EventDate >='$today' and hide=1) order by EventDate";
$result=odbc_exec($dbc,$query);
}

创建的函数如何不允许执行$result

我假设$dbc文件中的connect.php连接没有通过该函数。这看起来很奇怪。我在这里错过了一些简单的东西吗?

1 个答案:

答案 0 :(得分:0)

你的功能没有返回任何东西。

而不是:

function innerEvents() {
$query="SELECT * from events where( EventDate >='$today' and hide=1)order by EventDate";
$result=odbc_exec($dbc,$query);
}

您应该拥有以下内容:

function innerEvents() {
$query="SELECT * from events where( EventDate >='$today' and hide=1) order by EventDate";
return odbc_exec($dbc,$query);
}

$result = innerEvents();