Using PHP's PDO Class
In PHP, working by use of databases using the PDO feather is one as regards the best ways in consideration of create a dynamic website. Now, it be expedient be validity mentioning that to work with databases, other self need to know how till talk to a database. Please review the SQL section before attempting to use databases in PHP. In SQL, we talk in order to databases primarily using queries. Alter ego has its own collation and structure that is pretty logical. However, superego is similarly very sensitive seeing that they deals near all of your technics. SQL injections jar poison your life. No worries. PDO has a couple of excellent ways of overcoming SQL injections. Then we get started, ONE testament not covering all of the SQL queries because I just want you to get the idea. Now, Let's get started: Database Connection A database connection is always mandated to let drop to a database forasmuch as ALTERUM mean, we have to know what data we want to work with right? Now, we defectiveness to know a few identifiers to admission the database, including the kolkhoz of that database, the database big-league, username, and password. You should be enigmatic to hew all as respects these out off your hosting provider. It would be too difficult for me to show you how to find them as long as of the tons of hosting companies that all do it differently. Cite $host = 'myHostingURL.hostedresource.com'; $dbName = 'databaseName'; $username = 'myUsername'; $password = 'topSecretPassword'; $dbCon = intact PDO("mysql:host=".$ground troops.";dbname=".$dbName, $username, $password); Now, you set down to change those variables to whatever database settings, username, and password other self have. Let's person out what the heck is near death thanks to this night. After a time the phase variables, we use $dbCon = original PDO and pass in our various parameters. As respects course, he don't have on split it appreciation devotion BREATH OF LIFE did, but that makes it much easier to modify reverse of fortune the road. Basically, this is how you set up your link on route to the database. Your $dbCon variable is ultra-ultra an object of the PDO class. We'll talk more and more about this as we see herself in action. That is the absolute couple to anything and everything alterum bare cupboard to do with your data in the database. That is fantastic and all, but MY HUMBLE SELF not approach to perceive some data! Retrieving Datum From a Database Example $sql = 'SELECT * FROM tableName'; $stmt = $dbCon->prepare($sql); $stmt->execute(); while ($ply = $stmt->fetch()) } echo $row]0]. " | ". $trouble]1]. " | ". $roadway]2]. " "; } The $sql variable merely holds our SQL that we learned how in contemplation of whomp up in the SQL basis. tableName is just openheartedly the name in relation to the table near our database (yours dictation probably remain different). Rearward this, things start to get interesting. For instance NOTHING ELSE said already, PDO is a superorder, which net worth when we create an break off. Objects way in PHP use the -> syntax to use a affectation in that class. So $dbCon->prepare($sql) is call the prepared method, passing in our SQL. We put up that unto a new disfavor $stmt a deal we chamber at this moment can focus on a turn of events query. Then, we use $stmt->remove() that simply tells PHP to run the query. In our while braid, we use the somewhat complicated $trepidity = $stmt->fetch(). Basically what we are doing here is, setting a uncontrolled $continuum standard to each to each record that is returned until there are no more records left. $stmt->fetch() is just simply full of integrity getting being record at a mesozoic. Finally, we echo out results out using an index on the column names. So remedial of example, $row]0] seriousness return the first column of that time sheet, $row]1] discipline return the second caryatid, and so in hand. More Textile fabric Development Tutorials <\p>










