ESTATE
ESTATE
# Database connection
def connect_to_database():
return mysql.connector.connect(
host="localhost", # Replace with your MySQL host (e.g.,
'localhost')
user="root", # Replace with your MySQL username
password="password", # Replace with your MySQL password
database="estate_management"
)
query = "INSERT INTO estates (name, address, price, size, type) VALUES
(%s, %s, %s, %s, %s)"
cursor.execute(query, (name, address, price, size, estate_type))
connection.commit()
print(f"Estate '{name}' added successfully!")
cursor.close()
connection.close()
estates = cursor.fetchall()
cursor.close()
connection.close()
return estates
if name:
update_query += " name = %s,"
params.append(name)
if address:
update_query += " address = %s,"
params.append(address)
if price:
update_query += " price = %s,"
params.append(price)
if size:
update_query += " size = %s,"
params.append(size)
if estate_type:
update_query += " type = %s,"
params.append(estate_type)
cursor.execute(update_query, tuple(params))
connection.commit()
print(f"Estate with ID {estate_id} updated successfully!")
cursor.close()
connection.close()
connection.commit()
print(f"Estate with ID {estate_id} deleted successfully!")
cursor.close()
connection.close()
# Main program
if __name__ == "__main__":
# Example: Adding some estates
create_estate("Luxury Villa", "123 Sunset Blvd", 1200000.00, 450.00,
"Villa")
create_estate("City Apartment", "456 Main St", 500000.00, 85.00,
"Apartment")
# Display estates
display_estates()
Output:
+----+----------------+-------------------+-----------+-------+------------
+
| ID | Name | Address | Price | Size | Type
|
+----+----------------+-------------------+-----------+-------+------------
+
| 1 | Luxury Villa | 123 Sunset Blvd | 1200000.0 | 450.0 | Villa
|
| 2 | City Apartment | 456 Main St | 500000.0 | 85.0 | Apartment
|
+----+----------------+-------------------+-----------+-------+------------
+