I have to sql statements in functions to use in my code. Even though the echo
statements show the sql is valid the sql does not seem to execute and I get the
error, "PHP Warning: pg_fetch_object() expects parameter 1 to be resource,
boolean given in . . . line 154 . . ."
Line 154: while($val = pg_fetch_object($student))
##############################
Function Calls:
$insert = recordSentList($empid, $list, "printed"); // No record gets inserted
into the table
$student = getStudent($list);
while($val = pg_fetch_object($student)) //No records get listed
{
##############################
Functions:
function recordSentList($empid, $list, $method){
$today = date("m/d/Y", strtotime("now"));
$sql = "INSERT INTO lists_sent (
lists_sent_employers_id,
lists_sent_type,
lists_sent_date,
lists_sent_method)
VALUES (
'$empid',
'$list',
'$today',
'$method')";
echo "$sql<br />"; // slq statement looks accurate
$result = pg_query($conn,$sql);
echo "Insert Errors: " . pg_errormessage($conn) . "<br />";
//No errors are reported
return $result;
}
function getStudent($list){
$removaldate = date("m/d/Y",mktime(0, 0, 0, date("m")-3,
date("d")-7, date("Y")));
$sql = "SELECT * FROM students WHERE ";
if($list == "child_care_list"){
$sql .= "child_care_list > '" . $removaldate .
"' ";
$sql .= "AND child_care_list IS NOT NULL ";
$sql .= "ORDER BY student_lname ASC,
student_fname ASC";
} elseif ($list == "day_labor_list") {
$sql .= "day_labor_list > '" . $removaldate .
"' ";
$sql .= "AND day_labor_list IS NOT NULL ";
$sql .= "ORDER BY student_lname ASC,
student_fname ASC";
} else {
$sql .= "tutor_list > '" . $removaldate . "' ";
$sql .= "AND tutor_list IS NOT NULL ";
$sql .= "ORDER BY student_lname ASC,
student_fname ASC";
}
echo "$sql<br />"; // slq statement looks accurate
$result = pg_query($conn,$sql);
echo "Select Errors: " . pg_errormessage($conn) . "<br />";//No
errors are reported
echo "Rows: " . pg_num_rows($result) . "<br />";//No number is
displayed
if ((!$result) or (empty($result))){
return false;
}
return $result;
}
Marc Fromm
Information Technology Specialist II
Financial Aid Department
Western Washington University
Phone: 360-650-3351
Fax: 360-788-0251