PHP code example of mattsmithdev / pdo-crud-for-free
1. Go to this page and download the library: Download mattsmithdev/pdo-crud-for-free library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mattsmithdev / pdo-crud-for-free example snippets
php
// file: /src/Product.php
namespace <MyNameSpace>;
class Product extends \Mattsmithdev\PdoCrud\DatabaseTable
{
// private properties with EXACTLY same names as DB table columns
private $id;
private $description;
public function getDescription()
{
return $this->description;
}
}
php
// file: /public-web/index.php or /src/SomeController->method()
efined in order to create the DB connection
define('DB_HOST', '<host>');
define('DB_USER', '<db_username>');
define('DB_PASS', '<db_userpassword>');
define('DB_NAME', '<db_name>');
// get all products from DB as array of Product objects
$products = \<MyNameSpace>\Product::getAll();
// outputs something like:
// hammer, nail, nuts, bolts
foreach ($products as $product){
print $product->getDescription() . ', ';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.