Есть ли способ включить запрос MySQL в шаблон усы?

Я пытаюсь установить значения из запроса MySQL к шаблону в усах.
я использую mustache.php Можно ли сделать это? Я не могу найти документацию по шаблонным запросам. У кого-нибудь есть лучшее решение?

    <?php
/*
* PHP Mustache - Basic Mustache example in PHP
*/
$servername = "localhost";
$database = "laravel";
$username = "root";
$password = "root";

try {

$conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // set the PDO error mode to exception

} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}

$query = $conn->query('SELECT * FROM users');

//register mustache library
require 'Mustache/Autoloader.php';
Mustache_Autoloader::register();//set the template string (obviously complex application will use files)
$template = 'Hello, {{name}},<br /> Your last name is {{lastname}}';//set the template values
$values = array(
$query = $conn->query('SELECT * FROM users');
'name' = $row['name'];
'lastname' = $row['lastname'];
);//start the mustache engine
$m = new Mustache_Engine;

//render the template with the set values
echo $row['name'];
echo $row['lastname'];
echo $m->render($template, $values);
?>

0

Решение

Попробуйте это так

$statement = $conn->query('SELECT * FROM users');
$row = $statement->fetch(PDO::FETCH_ASSOC);

//start the mustache engine
$m = new Mustache_Engine;
echo $m->render($template, $row);
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]