YourLara-banner-Come-live-life-my-way

Fetch mysql results into an array using PHP

lara Avatar

Learn a bit of PHP, #phpBites

A simple connection to mysql database, and selecting from a table.

$connection = new \PDO('mysql:host='.$yourDbHost.';dbname='.$yourDbName, $yourDbUserName, $yourDbPassword);
$query = "SELECT col1, col2, col3, col4 FROM table WHERE col1 = :col1Value";
$stmt = $connection->prepare($query);
$stmt->execute([
':col1Value' => $contact_id,
]);
$result = $stmt->fetch();

Tagged in :

lara Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *