Skip to main content
edited body
Source Link
sunny
  • 1.8k
  • 1
  • 13
  • 29

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here. For example, a password that was not a real world and more than 4 letters in length. This is more of a teaching point to make sure everyone has some common sense!

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again? It could be helpful to show students they can do something in response to an error message apart from printing it out (like trying again, or waiting and trying again, or redirecting to a different page, or sending a warning email to the sys admin, etc).

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1,!

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here. For example, a password that was not a real world and more than 4 letters in length. This is more of a teaching point to make sure everyone has some common sense!

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again? It could be helpful to show students they can do something in response to an error message apart from printing it out (like trying again, or waiting and trying again, or redirecting to a different page, or sending a warning email to the sys admin, etc).

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1,

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here. For example, a password that was not a real world and more than 4 letters in length. This is more of a teaching point to make sure everyone has some common sense!

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again? It could be helpful to show students they can do something in response to an error message apart from printing it out (like trying again, or waiting and trying again, or redirecting to a different page, or sending a warning email to the sys admin, etc).

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1!

added 418 characters in body
Source Link
sunny
  • 1.8k
  • 1
  • 13
  • 29

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here. For example, a password that was not a real world and more than 4 letters in length. This is more of a teaching point to make sure everyone has some common sense!

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again? It could be helpful to show students they can do something in response to an error message apart from printing it out (like trying again, or waiting and trying again, or redirecting to a different page, or sending a warning email to the sys admin, etc).

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1,

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here.

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again?

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1,

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here. For example, a password that was not a real world and more than 4 letters in length. This is more of a teaching point to make sure everyone has some common sense!

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again? It could be helpful to show students they can do something in response to an error message apart from printing it out (like trying again, or waiting and trying again, or redirecting to a different page, or sending a warning email to the sys admin, etc).

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1,

Source Link
sunny
  • 1.8k
  • 1
  • 13
  • 29

I don't use PHP often, but here are a few comments:

Use Objects to Manage Resources

Like any other language with object-oriented capabilities, PHP serves you best when you manage resources with objects. I'd strongly recommend holding your PDO object within a custom class that manages the connection. This makes the code easier to maintain and doesn't actually have to change much about what you did. The code will also be more extensible. Also, introducing OOP is a very good lesson for students starting out.***

You could then also show them lazy-loading, making sure the PDO isn't opened until there is actually communicating between the server and the database.

Password length

Of course you'd want to point out to your students that you'd need a decent password and not the one you're using for illustrative purposes here.

Error handling

Perhaps show your students what you would really do with the error message. For example, how could they wait and call the connection again?

***I first learned to make a dynamic website with Robin Nixon's much villified book. When I first learned from it, I didn't understand why people poo-poo the book so much. The reason is that it gets folks off the on the wrong foot. I resisted object-oriented design for websites for a long time because I started with that book and wanted to keep things simple, but of course nothing stays simple for long. If I ever teach coding to beginners, I will start them with objects on day 1,