I created a MySQL database and a table within the database, I try to run the SQL in my app only to be met with an error which I have yet to see a fix for. It tells me that "Database survey.survey does not exist", yet when I open MySQL Workbench and check, both Database survey and Table people exist and I can edit it through Workbench but not Python. Is there a work around for this? I cannot seem to make it work no matter what I change or how I change it. Refer to my screenshots which show the errors and my Workbench setup which displays both the Database and the Table for it.
#๐ MySQL Database Error
39 messages ยท Page 1 of 1 (latest)
@shy beacon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
Are you sure you have a survey table? The screenshot doesn't show that.
Yes, let me show you
Actually my DATABASE is called survey.
I have a TABLE named people
Look
Database: survey
Table: people
Columns: name, age, gender, city
So, did you mean survey.people?
I don't regularly use SQL (we use Mongo), so I can't remember the exact notation, but the error indicates that you attempted to access a survey table, when you don't have such a table.
This is what I want to do:
I want to load the tables on screen from the database and display the user information. But when I load the data, I get a ton of errors.
Let me show you
It should read everything from the database and display it on the screen. Though it just crashes my app. I tried changing it from 'survey' to 'people' and the same crash happens. Its something with MySQL not liking python
you are doing FROM survay, that means that you are trying to access a table named survay, that is not the database name there
you want to use FROM people if your table is named people
I tried that but it didnt work either
as have already been noted by Carcigenicate the error message says survey.survey meaning database survey (which is correct) but table survey which is wrong
you even show us your people table
I think I fixed it though, for some reason the data wasnt loading for MySQL in PyCharm and it was causing a conflict. I deleted the table and remade it and it works now.
Idk what the error was LOL, I couldnt get it to load anything but I guess a good DROP command fixed it
Lets see it in action if itll work
you will probably get problems down the road if you use SELECT * in your code of your app, instead specify the tables names in the correct order that you want to fetch them in
otherwise if you alter or recreate the able later and it's not exactly as the table you got now you will get errors
I will try to specify more correctly once I get things a bit more polished. This is my first app I am making on my own that works. Im learning Python so I am bound to make horrid mistakes lol
okay, just see this as guidance for you, it's good to know this early on
I appreciate it ๐
I changed it and it works still ๐
that should be much more reliable
@shy beacon another thing to remember is to not interpolate or concatenate or similar strings that can be affected by a user in any way into an SQL statement, always use bind variables/placeholders for things that can be affected by a user
if that isn't possible (for example for column names or table names, use for example a lookup table to make exact comparisons to the input so be sure that it matches exactly what you expect and doesn't contain anything malicious/unexpected (SQL-injection attacks) that could be used to breach the security of your database
I understand the message: Dont expose yur data, but I am lacking in the terms you use. concatenate? interpolate? Idk what these mean lol. I understand SQL injection attacks but I dont think this app will become public, so I dont worry too much tbh
Regardless of how big you think the app will be, security issues are still security issues.
It's good practice to always use the proper technique and avoid this kind of exposure early.
concatenation is just when you add two or more strings together to form a single longer string
like the below uses + and += for concatenation
name = "Alice"
print("Hello " + name + "!")
interpolation is when you expand a variable or something that produces text within a string
for example using "f-strings" (format strings that begin with a f just before the opening quotes
name = "Bob"
print(f"Hello {name}!")
and as GraiceTurrble notes, it's good to get into good habits and practises regardless
Gotcha, I will look into the best and safest methods ๐ Thank you
Im going to close this since my problem is fixed, but I will message all of you privately if thats okay so I can talk more in depth in DM ๐ Thanks to you all โค๏ธ
!close
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.