Forked from Beteha/models/Model.php to standalone public library TPsoft/DBmodel,
added creator for build MODEL class, added basic tests
This commit is contained in:
28
test/test1.php
Normal file
28
test/test1.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../src/DBmodel.php';
|
||||
|
||||
$db = new \TPsoft\DBmodel\DBmodel('mysql:host=127.0.0.1;dbname=test;charset=utf8mb4', 'test', 'test');
|
||||
|
||||
// test query
|
||||
$result = $db->query("show tables");
|
||||
print_r($result);
|
||||
|
||||
// test results
|
||||
$result = $db->getAll("show databases");
|
||||
print_r($result);
|
||||
|
||||
$result = $db->getAll("show tables");
|
||||
print_r($result);
|
||||
|
||||
$result = $db->getCol("show tables");
|
||||
print_r($result);
|
||||
|
||||
$result = $db->getTableColumns("test");
|
||||
print_r($result);
|
||||
|
||||
$result = $db->getRow("select * from test where id = 10");
|
||||
print_r($result);
|
||||
|
||||
|
||||
?>
|
||||
12
test/test2.php
Normal file
12
test/test2.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../src/DBmodel.php';
|
||||
require_once __DIR__.'/../src/creator.php';
|
||||
|
||||
$db = new \TPsoft\DBmodel\DBmodel('mysql:host=127.0.0.1;dbname=test;charset=utf8mb4', 'test', 'test');
|
||||
|
||||
$creator = new \TPsoft\DBmodel\Creator($db);
|
||||
$creator->interact();
|
||||
|
||||
|
||||
?>
|
||||
38
test/test3.php
Normal file
38
test/test3.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../src/DBmodel.php';
|
||||
require_once __DIR__.'/../models/test.php';
|
||||
|
||||
$db = new \TPsoft\DBmodel\DBmodel('mysql:host=127.0.0.1;dbname=test;charset=utf8mb4', 'test', 'test');
|
||||
|
||||
$test = new Test();
|
||||
|
||||
// exists ID 11
|
||||
$result = $test->exist(11);
|
||||
print_r($result);
|
||||
|
||||
// insert new record
|
||||
$result = $test->test(null, array('name' => 'new record'));
|
||||
print_r($result);
|
||||
|
||||
// update record ID 11
|
||||
$result = $test->test(11, array('name' => 'updated record'));
|
||||
print_r($result);
|
||||
|
||||
// get record ID 11
|
||||
$result = $test->test(11);
|
||||
print_r($result);
|
||||
|
||||
// delete record ID 11
|
||||
$result = $test->test(11, null);
|
||||
print_r($result);
|
||||
|
||||
// get all records
|
||||
$result = $test->getList();
|
||||
print_r($result);
|
||||
|
||||
// get combined list of ID and name
|
||||
$result = $test->testCombo('id', 'name');
|
||||
print_r($result);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user