{"id":3714,"date":"2018-09-21T09:43:34","date_gmt":"2018-09-21T09:43:34","guid":{"rendered":"http:\/\/ebhor.com\/?p=3714"},"modified":"2021-02-19T07:05:41","modified_gmt":"2021-02-19T07:05:41","slug":"pdo-in-php","status":"publish","type":"post","link":"https:\/\/www.ebhor.com\/pdo-in-php\/","title":{"rendered":"PDO in PHP"},"content":{"rendered":"\n
Other than procedural methods like MySQLi, PHP also provides an object oriented approach to deal with databases. This framework is widely known as PDO: PHP Data Objects.<\/p>\n\n\n\n
PDO provides three error handling modes:<\/strong><\/p>\n\n\n\n The For installation procedure, visit: http:\/\/php.net\/manual\/en\/pdo.installation.php<\/a><\/p>\n\n\n\n Examples<\/strong><\/p>\n\n\n\n Database Connection Establishment using PDO<\/p>\n\n\n\n Here is an example using PDO:<\/p>\n\n\n\n Run Query Without variables<\/strong><\/p>\n\n\n\n For simple queries without PHP variable parameters, use the following PDO code:<\/p>\n\n\n\n Just change query for the simple DELETE, and INSERT statements within the above written code.<\/p>\n\n\n\n Run Query With PHP Variables<\/strong><\/p>\n\n\n\n For statements that take PHP variable parameters, Here we have performed three steps as follows:<\/p>\n\n\n\n N.B.: While binding parameters, never put quotes around the ‘?’ placeholders. It will cause SQL syntax errors because quotes aren’t needed to be known while preparing the query.<\/p>\n\n\n\n Read More<\/p>\n\n\n\n What is PDO? Other than procedural methods like MySQLi, PHP also provides an object oriented approach to deal with databases. This framework is widely known as PDO: PHP Data Objects. Advantages of PDO PDO is applicable on 12 different databases whereas MySQLi is not, which makes PDO more flexible than typical procedural approach. PDO also … Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[197,7],"yoast_head":"\nLimitation of PDO<\/h2>\n\n\n\n
PDO Set Up<\/h2>\n\n\n\n
\nsetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n\techo \"Connection Created successfully!\";\n\tcatch(PDOException $e)\n\t\t{\n\t\techo \"Connection failed: \" . $e->getMessage();\n\t\t}\n\n?>\n\n\n\n<\/pre>\n\n\n\n
\nexec(\"UPDATE table_name SET field_name='value'\");\necho $affected_rows . ' are affected';\n?>\n\n<\/pre>\n\n\n\n
\nprepare(\"SELECT * FROM table_name_Ebhor WHERE fld_id=? AND fld_name=?\");\n$qry->execute(array(\n\t$variable_id,\n\t$variable_name\n));\n$rows = $qry->fetchAll(PDO::FETCH_ASSOC);\n?>\n\n<\/pre>\n\n\n\n