Page 1 of 1

really helpful PHP tool / Github Copilot

Posted: 2022-07-10 11:42
by D Oliveira
Hi folks,

I have found a very useful tool that helps generating automatic PHP code for you: https://github.com/features/copilot

I just wrote this line:

Code: Select all

'''connect do the database tigercontrol2 and query the table worbook and print the result using mysqli'''
and this is the code it created:

Code: Select all

'''connect do the database tigercontrol2 and query the table worbook and print the result using mysqli'''
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tigercontrol2";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM worbook";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["surname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

// Path: test.php
'''connect do the database tigercontrol2 and query the table worbook and print the result using mysqli'''
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tigercontrol2";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM worbook";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["surname"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

// Path: test.php


Re: really helpful PHP tool / Github Copilot

Posted: 2022-08-05 14:21
by angus
looks really good, thanks for sharing