Reply to thread

To get started with composer simply go to https://getcomposer.org/. Then click [ICODE]Download[/ICODE] and find [ICODE]Download and run Composer-Setup.exe - it will install the latest composer version whenever it is executed.[/ICODE] Then click [ICODE]Composer-Setup.exe[/ICODE]. That will go through the installation process on your computer. Do not click developer mode, just click next. Then select you php engine from your xampp directory. For example, [ICODE]C:\xampp\php\php.exe[/ICODE]. Then click next. Skip the proxy settings. And then finally click [ICODE]install[/ICODE] and after it finishes click [ICODE]finish[/ICODE]. Then open a new command prompt. Then navigate to your xampp htdocs folder. You can use commands like [ICODE]cd ../[/ICODE] to go back on directory or [ICODE]cd xampp[/ICODE] to navigate to a folder. Then just type [ICODE]composer[/ICODE] and hit enter. [ATTACH=full]13193[/ATTACH]

You should get something similar to above. Then in that same directory type [ICODE]composer require paragonie/easydb:^2[/ICODE] and hit enter, that will install EasyDB. Once it has finished composer will generate a [ICODE]composer.json[/ICODE] and a [ICODE]composer.lock[/ICODE] in your htdocs folder and a vendor folder to contain the code you just installed. Then you can access the code doing this.

[CODE=php]<?php declare(strict_types=1);


require __DIR__ . '/vendor/autoload.php';


// Then you can now use EasyDB.


$db = \ParagonIE\EasyDB\Factory::fromArray([

    'mysql:host=localhost;dbname=something',

    'username',

    'putastrongpasswordhere'

]);


$rows = $db->run('SELECT * FROM comments WHERE blogpostid = ? ORDER BY created ASC', $_GET['blogpostid']);

foreach ($rows as $row) {

    $template_engine->render('comment', $row);

}

?>[/CODE]

Composer can be used to install useful packages from other developers so you don't have to reinvent the wheel when building your web application. Composer has more stuff you can do, read their documentation https://getcomposer.org/doc/01-basic-usage.md.

[automerge]1644087394[/automerge]

Also note some packages will require you to use a higher PHP version so if the package requires at least PHP 8 and you have PHP 7 composer will generate an error message. You can also learn more about the CLI commands here https://getcomposer.org/doc/03-cli.md.


Top