Skip to content

Instantly share code, notes, and snippets.

@dopsmain
Forked from dylanburkey/Slim App
Created February 2, 2017 09:11
Show Gist options
  • Save dopsmain/a3a9304bc60091f49eac6d8ad24e13f2 to your computer and use it in GitHub Desktop.
Save dopsmain/a3a9304bc60091f49eac6d8ad24e13f2 to your computer and use it in GitHub Desktop.
Slim MySQLi Integration
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim(); $app->get('/', function () use ($app) {
require_once 'lib/mysql.php';
$db = connect_db();
$result = $db->query( 'SELECT id, name, job FROM friends;' );
while ( $row = $result->fetch_array(MYSQLI_ASSOC) ) {
$data[] = $row;
}
$app->render('friends.php', array(
'page_title' => "Your Friends",
'data' => $data
)
);
});
$app->run();
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim(); $app->get('/', function () use ($app) {
require_once 'lib/mysql.php';
$db = connect_db();
$result = $db->query( 'SELECT id, name, job FROM friends;' );
while ( $row = $result->fetch_array(MYSQLI_ASSOC) ) {
$data[] = $row;
}
$app->render('friends.php', array(
'page_title' => "Your Friends",
'data' => $data
)
);
});
$app->run();
$app->get('/', function () use ($app) {
require_once '../lib/dbconnect.inc.php';
$db = dbConnect('read');
$result = $db->query( 'SELECT * FROM le_pages;' );
while ( $row = $result->fetch_array(MYSQLI_ASSOC) ) {
$data[] = $row;
}
$app->render('index.html', array(
'page_title' => "Your Friends",
'data' => $data
)
);
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment