Attendence System - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Attendence System (/thread-1189.html) Pages:
1
2
|
RE: Attendence System - nilamo - Dec-20-2016 You should post some more code. It looks like you haven't connected to the database yet. RE: Attendence System - elliott0184 - Dec-20-2016 Ok didnt know how much i should post. The Mysql server is on the same machine i am using to write the code. import time import mysql.connector from mysql.connector import errorcode from datetime import datetime try: cnx = mysql.connector.connect(user='root',database='staff', host='localhost') except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your username or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) else: cnx.close() cursor = cnx.cursor()Thats when i receive the error.
RE: Attendence System - wavic - Dec-20-2016 Do you have privileges to connect to the db? RE: Attendence System - elliott0184 - Dec-20-2016 (Dec-20-2016, 06:30 PM)wavic Wrote: Do you have privileges to connect to the db? I think i do how would i check from the mysql console? + shouldnt it give me a error if i couldn't on the line above? RE: Attendence System - nilamo - Dec-20-2016 Try pinging the server after you've got a connection, but before trying to make a cursor. That way you can make sure the database is running and you're connected. https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-ping.html You could also skip the cursor and use the connection directly with .cmd_query(): https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-cmd-query.html RE: Attendence System - elliott0184 - Dec-21-2016 (Dec-20-2016, 06:41 PM)nilamo Wrote: Try pinging the server after you've got a connection, but before trying to make a cursor. That way you can make sure the database is running and you're connected. https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-ping.html ok so i tried to ping the server and i still gives me a big error. NEW code import time import mysql.connector from mysql.connector import errorcode from datetime import datetime try: cnx = mysql.connector.connect(user='root', password='password', database='staff', host='localhost') except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your username or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) else: cnx.close() cnx.ping(attempts=1,delay=0)Then i get the error Sorry for the big errors and for me being not very good at python. :) I have learned loads over the last few days and i thank you all for your help.
RE: Attendence System - Larz60+ - Dec-21-2016 Looks to me like the server is not running RE: Attendence System - elliott0184 - Dec-21-2016 (Dec-21-2016, 01:36 PM)Larz60+ Wrote: Looks to me like the server is not running I can access the server from the console though. i start the server from the terminal and then i can access it. I presume that means it is up? RE: Attendence System - elliott0184 - Dec-21-2016 Ok problem solved. I started up a apache server on the same PC and it seemed to fix it. Don't really Understand but it now works. Thanks very much. RE: Attendence System - elliott0184 - Feb-21-2017 Ok so thought I would use the same thread even though I am much further on. Now I am looking at the clocking out section. I have managed to get the system to get them to input their staff id twice. it then goes to check the server. if it finds the right code in one of the MYSQL tables it returns saying clocked it. It then adds a row to a different table with the date in one column, the "time in" in another and their name in the last. How do I get it to check if they are already clocked in that day and if they are, clock them out by adding a time into the clock out column. Any help would be great thanks |