Posts

Showing posts from December, 2023

CRUD operation in Database using PHP

  PDO replaces all previous database interaction approaches. Using PDO, you could easily perform CRUD and related DBMS operations. In effect, PDO acts as a layer separating database-related operations from the rest of the code. Connectivity One of the most important benefits of PDO is the simple database connectivity. Consider the following code snippet used to set up connections with the database. <?php $server = “localhost”; $user = “root”; $password = “”; $db = “phppdo”; try { $dbcon = new PDO(“mysql:host=$server;dbname=$db”, $user, $password); $dbcon->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_OBJ); } catch (PDOException $e) { echo “Connection Failed: “ . $e->getMessage(); } In the above code snippet, notice that the DBMS is MySQL. However, if the DBMS changes to MS SQL Server, the only change will be the replacement of MySQL with mssql. Creating a Table With PDO To create a table, first declare a query string and then execute it with the exec function as no ...