ramiwahdan Posted March 16, 2020 Share Posted March 16, 2020 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 16, 2020 Share Posted March 16, 2020 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) . Quote Link to comment Share on other sites More sharing options...
ramiwahdan Posted March 16, 2020 Author Share Posted March 16, 2020 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 "); Quote Link to comment Share on other sites More sharing options...
Barand Posted March 16, 2020 Share Posted March 16, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.