PDO Assistance

Hi,
Is the following correct or have i got it 100% wrong :’(

Assigned Tickets = <?php $sql = "Select Count(*) FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0;" $stmt = $pdo->query($sql); $stmt->([$count]); $jobcomp = $stmt->fetch(); ?>

[/php]

My php error log also shows this:
[05-Apr-2018 09:38:48 UTC] PHP Warning: PHP Startup: Unable to load dynamic library ‘php_pdo_sqlsrv_72_ts.dll’ (tried: C:\php\ext\php_pdo_sqlsrv_72_ts.dll (The specified module could not be found.), C:\php\ext\php_php_pdo_sqlsrv_72_ts.dll.dll (The specified module could not be found.)) in Unknown on line 0
[05-Apr-2018 09:38:48 UTC] PHP Warning: PHP Startup: pdo_sqlsrv: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20170718
These options need to match
in Unknown on line 0
[05-Apr-2018 09:38:48 UTC] PHP Parse error: syntax error, unexpected ‘$stmt’ (T_VARIABLE) in C:\inetpub\wwwroot\SupportDesk\php\Index.php on line 35

The errors in the PHP error log suggest my PDO is broken but the strange thing is if i comment out the code as there are 2 include statements that is my navbar and my SQLconnection and some other checks it works fine and a clean error log.

Personally i think its the code for my assigned ticket count the Select query works as i have tested it in SQLMAN studio.

Thanks for all your help.

Cheers James

[05-Apr-2018 09:38:48 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_72_ts.dll'

PHP can’t find the dll it needs for PDO MSSQL

[05-Apr-2018 09:38:48 UTC] PHP Parse error:  syntax error, unexpected '$stmt' (T_VARIABLE) in C:\inetpub\wwwroot\SupportDesk\php\Index.php on line 35

You’re missing (or have misplaced) the ending semi colon in your query
[php]$sql = “Select Count(*) FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0;” // this line never ends[/php]

Thanks JimL,

I still dont understand if my SQLSRV_72_ts.dll was missing my DB connections script wouldnt work.
$conn = new PDO(“sqlsrv:server=PCNAME\SUPPORTDB; database=SUPPORT_DB”,$user, $pass);
With below code commented out my PHP errors log i get no errors a blank notepad file.
But uncommenting the below code:

<?php $sql = "Select Count(*) FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0;"; $stmt = $pdo->query($sql); $stmt->([$count]); $jobcomp = $stmt->fetch(); ?>

It throws the error [05-Apr-2018 12:28:06 UTC] PHP Warning: PHP Startup: Unable to load dynamic library ‘php_pdo_sqlsrv_72_ts.dll’ (tried: C:\php\ext\php_pdo_sqlsrv_72_ts.dll (The specified module could not be found.), C:\php\ext\php_php_pdo_sqlsrv_72_ts.dll.dll (The specified module could not be found.)) in Unknown on line 0
[05-Apr-2018 12:28:06 UTC] PHP Warning: PHP Startup: pdo_sqlsrv: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20170718
These options need to match
in Unknown on line 0
[05-Apr-2018 12:28:06 UTC] PHP Parse error: syntax error, unexpected ‘(’, expecting identifier (T_STRING) or variable (T_VARIABLE) or ‘{’ or ‘$’ in C:\inetpub\wwwroot\SupportDesk\php\Index.php on line 40

But surely it should throw the module not found with or with out the other code not being there.

Or is my line 40 piece of code $stmt->([$count]); throwing the hole error.

Thanks James

Update ---------- :stuck_out_tongue: :stuck_out_tongue:
The missing modules is a bogus error i commented out line 40 [php]$stmt->([$count]);[/php] and the error went.
Basically i am trying to query my SQL express DB using PDO and then produce the number returned on my index.php for assigned tickets.
[php]

Assigned Tickets = <?php
$sql = “Select Count(*) FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0;”;
$stmt = $pdo->query($sql);
$stmt->([$count]);
$jobcomp = $stmt->fetch();
echo “$jobcomp”;
?>


View Tickets »


[/php]
The Idea is when they click on view tickets i will be able to show the Assigned tickets on another page.

My PHP is pretty basic but its something i would like to get to grips with while developing this site.

Thanks inadvance

James

I don’t know what you are expecting from,
[php] $stmt->([$count]);[/php]

Using the query method, the results are returned to it. So, no fetch is required either. I would expect you want to dump what that variable is holding to see what it contains,
[php]print_r($stmt);[/php]

Thanks astonecipher.
print_r($stmt);
returns the following: PDOStatement Object ( [queryString] => Select Count(*) FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0; )

not the number of jobs that are not completed.

All i want to do is query the SQLDB and then Assigned tickets show how may jobs are open and then i can work on the other areas working with PDO seems more difficult than older versions of connecting :’( :’( :’( :’(

I am going try and piece it together back to PHPmanual and Google…

Thanks in advance

James

[php]
$sql = “Select Count(*) FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0;”;
$stmt = $pdo->prepare($sql);
$stmt->execute();

$result = $stmt->fetchColumn();
echo $result;
[/php]

Thanks Astonecipher thats what i need… :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue:

Now using this code:

[code]$sql = “Select * FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0;”;
$stmt = $pdo->prepare($sql);
$stmt->execute();

$result = $stmt->fetchColumn();
echo $result;
[/code]

I need to change my $result to be able to fetch all the 62 coloums picked from the select statement and enter them in table.

I know it will be a do while cmd but i will tackle this tommorow or later tonight.

Thank you to all thats has helped so far very much appricated.

Thanks James

To do that, you need to make a few changes, but we will get there when you are ready for it.

Hi Astonecipher,

Ok, i will have a read up on how best to execute this again i have the SQL statement its just working out the PHP.

Thanks James

Sponsor our Newsletter | Privacy Policy | Terms of Service