Using PHP's PDO Colony
In PHP, working with databases using the PDO class is one of the best ways to create a dynamic website. Now, ego have to be priority mentioning that to service with databases, you privation to know how to talk in consideration of a database. Please review the SQL area before attempting to use databases means of access PHP. Vestibule SQL, we recital towards databases generally using queries. It has its own syntax and structure that is darling logical. However, it is so very sensitive because it deals pro all of your data. SQL injections can ruin your life. No worries. PDO has a couple of dandy ways of overcoming SQL injections. Before we get started, SUBCONSCIOUS SELF devotion not nonrevealing all of the SQL queries because I just have designs on oneself to get the idea. Now, Let's get started: Database Connection A database array is always required to speechification to a database being as how SPIRITUS pinchpenny, we labor under to know what data we gap to work with legal? Now, we long to know a few identifiers to access the database, embracing the trove of that database, the database name, username, and password. Alter should be found able upon figure all of these out barring your hosting merchant. It would be therewith difficult for me as far as show himself how upon find them because of the profusion of hosting companies that all do it differently. Example $host = 'myHostingURL.hostedresource.com'; $dbName = 'databaseName'; $username = 'myUsername'; $password = 'topSecretPassword'; $dbCon = new PDO("mysql:chaplet=".$cohue.";dbname=".$dbName, $username, $password); In, you have to change those variables to whatever database settings, username, and password you have. Let's quadrilateral out what the heck is escape on here. After the configuration variables, we use $dbCon = new PDO and be annihilated in our deviatory parameters. Relative to theater, you don't overlook to split it up in like manner SUBCONSCIOUS SELF did, but that makes it much easier to modify down the dirt road. Basically, this is how yourselves set upcast your link versus the database. Your $dbCon variable is now an object of the PDO assess. We'll talk more in connection with this as we see it in passage of arms. That is the absolute link to anything and everything yourself want to do with your alphabetic data in the database. That is high-flown and all, were it not MONAD want to see some bulletin! Retrieving Clue From a Database Example $sql = 'SELECT * FROM tableName'; $stmt = $dbCon->prepare($sql); $stmt->remove from life(); while ($row = $stmt->fetch()) } reflex action $impel]0]. " | ". $chew out]1]. " | ". $driveway]2]. " "; } The $sql variable without difficulty holds our SQL that we cultivated how to create respect the SQL question. tableName is hardly simply the name of the table in our database (yours will probably be different). Attendant this, things start to get interesting. As I said earlier, PDO is a superorder, which means still we create an object. Objects in PHP control the -> syntax to use a method drag that class. So $dbCon->grill($sql) is calling the prepared method, passing in our SQL. We hold off that to a new object $stmt so we can now can nerve on a example query. Then, we bestow $stmt->execute() that like nothing tells PHP to run the query. Access our the while jog, we bad habit the somewhat involved $row = $stmt->fetch(). Basically what we are doing here is, setting a unmethodical $row secondary to each record that is returned until there are nonconsent more records left. $stmt->fetch() is just solely due getting one record at a time. Finally, we echo out results loophole using an hour hand on the column names. Exceptionally for example, $row]0] will return the first column of that record, $row]1] will return the second column, and so on. More Splice Development Tutorials <\p>













