PHP
--
Questions
--
Followers
Top Experts
Please advise
<?PHP
error_reporting(E_ALL ^ E_NOTICE);
include '/www/vhosts/localhost/attendance/components/db_conx.php';
$course_attendance_query = "SELECT ClassDates.ClassId
,ClassDates.ClassDate
,UserId
,ClassDates.DateRecord
,AttendValue
FROM attendance_bb.dbo.AttendRecs
,attendance_bb.dbo.ClassDates
WHERE attendance_bb.dbo.AttendRecs.DateRecord = attendance_bb.dbo.ClassDates.DateRecord
AND SUBSTRING(attendance_bb.dbo.ClassDates.ClassId,2,LEN(attendance_bb.dbo.ClassDates.ClassId)-3) IN (34290, 34294, 34295)
AND attendance_bb.dbo.ClassDates.ClassDate >= '2015-04-27'
AND attendance_bb.dbo.AttendRecs.UserId NOT LIKE ('coordinator_%')
AND attendance_bb.dbo.AttendRecs.UserId NOT LIKE ('dd_%')
AND attendance_bb.dbo.AttendRecs.UserId NOT LIKE ('dpc_%')
AND attendance_bb.dbo.AttendRecs.UserId NOT LIKE ('15%')
ORDER BY SUBSTRING(attendance_bb.dbo.ClassDates.ClassId,2,LEN(attendance_bb.dbo.ClassDates.ClassId)-3) ASC
,attendance_bb.dbo.ClassDates.ClassDate ASC
";
echo "$course_attendance_query<br>\n\n";
$bbsql1_sqlsrv_database='attendance_bb';
$bbsql1_sqlsrv_connect = connect_to_bbsql1($bbsql1_sqlsrv_database);
$params = array();
$options = array( "Scrollable" => 'buffered' );
$course_attendance_result = sqlsrv_query($bbsql1_sqlsrv_connect, $course_attendance_query, $params, $options);
if (!$course_attendance_result)
{
echo "There is a problem with course_attendance_query: \n $course_attendance_query \n\n<br><br>";
if (($errors = sqlsrv_errors()) != null)
{
foreach( $errors as $error )
{
echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
echo "code: ".$error[ 'code']."<br />";
echo "message: ".$error[ 'message']."<br />";
}
}
exit;
echo "\n\n\n";
}
echo "Beginning of var_dump:<br>";
var_dump($course_attendance_result);
echo "<br>End of var_dump<br><Br>";
echo "Results:<br>" . $course_attendance_result . "<Br><br>";
$n = 1;
$viewable_clicks = 0;
$course_attendance_num_rows = sqlsrv_num_rows($course_attendance_result);
echo "course_attendance_num_rows =" . $course_attendance_num_rows . "----()<br>";
while ($course_attendance_row = sqlsrv_fetch_array($course_attendance_result, SQLSRV_FETCH_ASSOC))
{
$course_attendance_row = array_map('trim', $course_attendance_row);
$ClassId = $course_attendance_row['ClassId'];
$ClassId_break = explode("_",$ClassId);
$crsmain_pk1 = $ClassId_break[1];
$ClassDate = date("Y-m-d", strtotime($course_attendance_row['ClassDate']));
$UserId = $course_attendance_row['UserId'];
$DateRecord = $course_attendance_row['DateRecord'];
$AttendValue = $course_attendance_row['AttendValue'];
$bbsql1_sqlsrv_database='bblearn';
$bbsql1_sqlsrv_connect = connect_to_bbsql1($bbsql1_sqlsrv_database);
$find_student_info_query = "SELECT firstname
,lastname
FROM users
WHERE batch_uid = '$UserId'
";
echo "$n - $find_student_info_query<br>";
$n++;
}
?>
Here is what I'm getting on my page:
Connected to AS400 correctly
Connected to MySQL correctly
Able to connect to bblearn on sql1-64
Able to connect to attendance on SQLSRV01\SQLSERVER
SELECT ClassDates.ClassId ,ClassDates.ClassDate ,UserId ,ClassDates.DateRecord ,AttendValue FROM attendance_bb.dbo.AttendRe
Able to connect to attendance_bb on bbsql1-64
Beginning of var_dump:
resource(9) of type (SQL Server Statement)
End of var_dump
Results:
Resource id #9
course_attendance_num_rows
Able to connect to bblearn on bbsql1-64
1 - SELECT firstname ,lastname FROM users WHERE batch_uid = 'XXXXXXX'
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
How do I change the database that I'm querying then? I'm using an attendance_db in the first part then bblearn in the second.
I figured it out... I changed the variable and it worked.
Thanks a lot, this has been driving me crazy. I'm used to in MYSQL and MSSQL to be able to just change the DB and not have to redo the connection string.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
The old way I was doing I was using the mssql_select_db and changing it back and forth inside the while loop and it still worked fine.
Thanks a lot for the information and guidance.
WT

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
PHP
--
Questions
--
Followers
Top Experts
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.