PHP code example of utipd / mysqlmodel
1. Go to this page and download the library: Download utipd/mysqlmodel 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/ */
utipd / mysqlmodel example snippets
// create a class
// this maps to table user in MySQL (you must create this yourself)
class UserDirectory extends \Utipd\MysqlModel\BaseDocumentMysqlDirectory {
protected $column_names = ['email'];
}
// pass in your PDO object
$user_directory = new UserDirectory(new \PDO('mysql:dbname=testdb;host=127.0.0.1'));
// find by email
$user = $user_directory->findOne(['email' => '[email protected]']);
// access rows and properties
print $user['email']."\n";
// update in MySQL, adding arbitrary columns
$user_directory->update($user, ['firstName' => 'John', 'lastName' => 'Appleseed']);
// get the user again from the database
$user = $user_directory->reload($user);
print $user['firstName']." ".$user['lastName']."\n";