PHP tester allows to test PHP code Online without install. You can test your code easily and quickly. You can test PHP 8 :)
You can test PHP MySQL with PDO, and also test PHP Sodium (PHP 7.4.8 and PHP 8 Only).
To execute your code, you must copy and paste, drag and drop a PHP file or directly type in the "PHP code" online editor below, and click on "Run" button.
$dsn = "mysql:host=mysql;dbname=php_tester";
$user = "php_tester";
$passwd = "password";
$pdo = new PDO($dsn, $user, $passwd);
$stm = $pdo->query("SELECT '1' as id, 'Albert' as name UNION SELECT '2' as id, 'Isaac' as name UNION SELECT '3' as id, 'Marie' as name ");
$rows = $stm->fetchAll(PDO::FETCH_NUM);
foreach($rows as $row) {
echo(json_encode($row)."\n");
}
// Connect to phpTester database
$manager = new MongoDB\Driver\Manager("mongodb://php-tester:123@localhost:27017/phpTester");
// Insert a document
$bulkWrite=new MongoDB\Driver\BulkWrite;
$doc=array("title" => "PHP Tester", "description" => "Test PHP code online");
$bulkWrite->insert($doc);
$manager->executeBulkWrite('phpTester.example', $bulkWrite);
// Get all documents
$query = new MongoDB\Driver\Query(array());
$cursor = $manager->executeQuery('phpTester.example', $query);
// Convert to Array and print result
print_r($cursor->toArray());
// Delete all documents
$bulkDelete = new MongoDB\Driver\BulkWrite;
$bulkDelete->delete(['title' => 'PHP Tester' ], ['limit' => 0]);
$manager->executeBulkWrite('phpTester.example', $bulkDelete);