What are the differences in connecting to Oracle vs MySQL databases in PHP?
Connecting to Oracle and MySQL databases in PHP involves using different PHP extensions and connection strings. For Oracle, you need to use the OCI8 extension and provide the appropriate connection details specific to Oracle. For MySQL, you would use the MySQLi or PDO extension and the MySQL-specific connection details. For connecting to Oracle database in PHP:
// Oracle database connection settings
$tns = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port))(CONNECT_DATA=(SID=sid)))";
$username = "username";
$password = "password";
// Connect to Oracle database
$conn = oci_connect($username, $password, $tns);
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
```
For connecting to MySQL database in PHP using MySQLi extension:
```php
// MySQL database connection settings
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}