version.php

PHOTO EMBED

Thu Sep 08 2022 09:13:05 GMT+0000 (Coordinated Universal Time)

Saved by @vmap #php #mysql #pdo

<?php

//These variables are used to create a connection string to the database. The dsn is the Data Source Name, which contains the information required to connect to the database.
$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";

//A new PDO object is created. We pass the constructor the data source name and the user name and password. The PDO class represents a connection between PHP and a database server.
$pdo = new PDO($dsn, $user, $passwd);

//The query method executes an SQL statement in a single function call. It returns the result set.
$stm = $pdo->query("SELECT VERSION()");

//The PDO statement's fetch method fetches the next row from a result set. In our case it is a version of MySQL.
$version = $stm->fetch();

//The $version is an array; we get its first value.
echo $version[0] . PHP_EOL;

?>
content_copyCOPY

https://zetcode.com/php/pdo/