SQL PDO


#1

Hi ,

Can someone please let me know where i am going wrong with this code.

I just cannot seee where i am going wrong or if anyone can suggest a better way of doing it.

My connections files is a seperate php file code below and is on a include function
[php]

<?php $user ="********"; $pass ="********"; $conn = new PDO("sqlsrv:server=********\SUPPORTDB; database=SUPPORT_DB",$user, $pass); ?>

[/php]
The code i am running is
[php]

<?php $sql = "Select [Job Number],[Customer],[Type of Equipment],[model],[Fault],[Location],[Date Reported],[Time Reported],[Reported by],[Attended by], [Action Taken] FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::fetch_Assoc); ?>
		<table class="table">
		<tr>
		<th>Job Number</th>
		<th>Customer</th>
		<th>Type Of Equipment</th>
		<th>Model</th>
		<th>Fault</th>
		<th>Location</th>
		<th>Date Reported</th>
		<th>Time Reported</th>
		<th>Reported By</th>
		<th>Attended By</th>
		<th>Action Taken</th>
		</tr>
		<?php foreach ($results as $row) {
			echo "<tr><td>";
			echo $row['Job Number'];
			echo "</td><td>";
		    echo "<tr><td>";
			echo $row['Customer'];
			echo "</td><td>";
			echo "<tr><td>";
			echo $row['Type Of Equipment'];
			echo "</td><td>";
			echo "<tr><td>";
			echo $row['Model'];
			echo "</td><td>";
			echo "<tr><td>";
			echo $row['Fault'];
			echo "</td><td>";
		}
		?>
		</table>

[/php]

My Php error log informs me of the below:

[11-Apr-2018 15:36:04 UTC] PHP Fatal error: Uncaught Error: Undefined class constant ‘fetch_Assoc’ in C:\inetpub\wwwroot\SupportDesk\php\Assigned_Tickets.php:20
Stack trace:
#0 {main}
thrown in C:\inetpub\wwwroot\SupportDesk\php\Assigned_Tickets.php on line 20

Which is Line:[php] $results=$stmt->fetchAll(PDO::fetch_Assoc); [/php]

Thanks inadvance

James


#2

I have managed to get the data now to show

my PDO::FETCH_ASSOC wasnt in uppercase

[php]$results=$stmt->fetchAll(PDO::FETCH_ASSOC);[/php]

but it doesnt present in a table more just on coloum.

Any help appreciated.

Thanks James


#3

PHP is case sensative. fetch_Assoc, is a constant variable. That means, it is all caps. What you have, doesn’t exist so the script can’t find it.


#4

Manged to resolve my issues thanks for the help.