Jump to content
#FlattenTheCurve ×
ramiwahdan

pdoConnect error

Recommended Posts

Hi,

I am trying to use PDO but i am stuck, what is the problem?

code:

<?php


$servername = "localhost";
$username = "someuser";
$password = "somepassword";

    $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$db = pdoConnect('test');

i get error: 

Fatal error: Uncaught Error: Call to undefined function pdoConnect() in E:\xampp\htdocs\AttendanceSystem\total.php:12 Stack trace: #0 {main} thrown in E:\xampp\htdocs\AttendanceSystem\total.php on line 12

 

Share this post


Link to post
Share on other sites

pdoConnect() is my custom function which does what you have already done in the lines above it. Remove that line and replace $db in my code with $conn (as that is the connection you are creating) .

Share this post


Link to post
Share on other sites
1 hour ago, Barand said:

pdoConnect() is my custom function which does what you have already done in the lines above it. Remove that line and replace $db in my code with $conn (as that is the connection you are creating) .

Thank you, its working now. as for the select statement how to add where clause?

$res = $conn->query("SELECT oracleid
                         , name 
                         , des 
                         , clockingindate   as clockin
                         , clockingoutdate  as clockout
                         , timediff(clockingoutdate, clockingindate) as duration
                         , total
                    FROM attendance_records (where isdone = -1)
                         JOIN (
                                SELECT oracleid
                                     , sec_to_time(sum(timestampdiff(SECOND, clockingindate, clockingoutdate))) as total
                                FROM attendance_records
                                GROUP BY oracleid
                              ) tots USING (oracleid)
                    ORDER BY oracleid, clockingindate
                    ");

 

Share this post


Link to post
Share on other sites
1 hour ago, ramiwahdan said:

how to add where clause?

Typing it is a good way. Put it after the FROM section and before the ORDER BY.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.