From ef2be456d32fb03b27e4bf37c5940239306cec57 Mon Sep 17 00:00:00 2001 From: Hovhannes Date: Mon, 1 Apr 2019 03:46:10 +0200 Subject: [PATCH] Example of simple PDO Connection (#28888) * Example of simple PDO Connection * Update index.md --- .../php/working-with-databases/index.md | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/guide/english/php/working-with-databases/index.md b/guide/english/php/working-with-databases/index.md index a7cd008fe3..9bdfe6041f 100644 --- a/guide/english/php/working-with-databases/index.md +++ b/guide/english/php/working-with-databases/index.md @@ -14,9 +14,26 @@ PHP Data Objects (PDO) and MySQLi Object Orientated along with the now deprecate With PHP there are many features built into the core functionality of the language that make links to a database simple and easy. -Some Examples from Mysqli are- +### Example of MYSQL Connection +Here we are connecting to a database on the phpmyadmin structure, with no password, and database named `db_name`. ```php $con=mysqli_connect("localhost","root","","db_name") or die("Invalid User or Password...cannot connect"); ``` -Here we are connecting to a database on the phpmyadmin structure, with no password, and database named `db_name`. + +### Example of PDO Connection +``` +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "Connected successfully"; +} catch(PDOException $e) { + echo "Connection failed: " . $e->getMessage(); +} +?> +```