Here, we are using PDO (PHP Data Objects) to create a MySQL connection. We then check if there are any errors. If there are none, we print "connected Successfully" or else, we print "connection failed" followed by the error thrown by PDO.
Here, we are using pg_connect() method to connect to a postgres database. We can choose to either define the database details in variables or inline directly.
3) Connecting with SQLite database in PHP
<?php
class MyDB extends SQLite3 {
function __construct() {
$this->open('example.db');
}
}
?>
Here, we are creating a new Class (myDB) which extends to the SQLite3 extension. __construct function is used to create an array that holds the example.db SQLite database.
1) Connecting with MySQL in PHP
Here, we are using PDO (PHP Data Objects) to create a MySQL connection. We then check if there are any errors. If there are none, we print "connected Successfully" or else, we print "connection failed" followed by the error thrown by PDO.
2) Connecting with postgres in PHP
Here, we are using pg_connect() method to connect to a postgres database. We can choose to either define the database details in variables or inline directly.
3) Connecting with SQLite database in PHP
Here, we are creating a new Class (myDB) which extends to the SQLite3 extension. __construct function is used to create an array that holds the example.db SQLite database.
need an explanation for this answer? contact us directly to get an explanation for this answer