PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
<?php $host = 'localhost'; // Database host $user = 'root'; // MySQL username $password = ''; // MySQL password (default is empty in XAMPP) $dbname = 'library_db'; // Database name // Create a connection to the MySQL database try { $conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $password); // Set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>
Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; $now = Carbon::now()->format('d/m/Y'); printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion()); $query = "SELECT VERSION() as version;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('DB version (PDO): %s ' . PHP_EOL, $row['version']); // Run query using mysqli $result = $mysqli->query($query); $version = $result->fetch_object(); printf('DB version (mysqli): %s ' . PHP_EOL, $version->version); // Select using Laravel $version = $db::select($query); printf('DB version (Laravel Query Builder): %s ' . PHP_EOL, $version[0]->version);
Show:  
Copy Clear