itsgoingd / clockwork

Clockwork - php dev tools in your browser - server-side component
https://underground.works/clockwork
MIT License
5.62k stars 323 forks source link

ClockWork to Vanilla php application #650

Open kochivai opened 11 months ago

kochivai commented 11 months ago

I am trying to add clockwork in vanilla php application. so trying to add in a just index.php file. but it does not show any data to the browser extension or toolbar.

how to install clockwork in a vanilla php application. my code:

<?php require_once 'vendor/autoload.php'; use Clockwork\Support\Vanilla\Clockwork;

$clockwork = Clockwork::init (); $db_type = 'pgsql'; $dbConn = "localhost"; $dbName = "ossDB"; $db_user = "postgres"; $db_pass = "1234"; $db_port = 5432;

function qry($qry, $return = 1){ global $dbConn, $dbName, $db_user, $db_pass, $db_type, $db_port, $clockwork; try { $dsn = "$db_type:host=$dbConn;port=$db_port;dbname=$dbName;user=$db_user;password=$db_pass"; $myPDO = new PDO($dsn); } catch (PDOException $e) { echo $e->getMessage(); }

if ($return == 0) {
    $statment = $myPDO->prepare($qry);
    $statment->execute();
} else {
    $start_time = microtime(true); // Record start time
    $statment = $myPDO->prepare($qry);
    $statment->execute();
    $QueryArray = $statment->fetchAll(PDO::FETCH_ASSOC);
    $end_time = microtime(true); // Record end time
    $execution_time = ($end_time - $start_time); // Calculate execution time in milliseconds
    // Capture the SQL query data and send it to Clockwork
    $queryData = [
        'query' => $qry,
        'bindings' => [],
        'time' => $execution_time,
    ];
    $clockwork->addDatabaseQuery($queryData);
    return $QueryArray;
}

} $users = qry("SELECT * FROM users"); ?> <!DOCTYPE html>

Document requestProcessed(); ?>
itsgoingd commented 11 months ago

Hey, you can find installation instructions for vanilla apps on the Clockwork website - https://underground.works/clockwork/#docs-installation-vanilla