9951 explained code solutions for 126 technologies


php-pdoTest PHP PDO connection


$pdo = new PDO('mysql:host=localhost;dbname=test', 'usr', 'pwd');
$now = $pdo->query('SELECT NOW()')->fetchColumn();ctrl + c
new PDO

create new PDO connection

query(

executes specified SQL and return PDOStatement

SELECT NOW()

DB will return current date and time

fetchColumn

will return single column value

$now

if this variable contains date/time, our connection is fine