-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
49 lines (39 loc) · 1.36 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php /** @noinspection PhpUnhandledExceptionInspection */
use eftec\bladeone\BladeOne;
use eftec\PdoOne;
include "vendor/autoload.php";
$pdoOne=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');
$pdoOne->connect();
// Does the table exist?
if (!$pdoOne->tableExist('test_products')) {
// No, then let's create a new table
$pdoOne->createTable('test_products'
,['idProduct'=>'int not null','name'=>'varchar(50)']
,['idProduct'=>'PRIMARY KEY']);
// and let's add some example data
$pdoOne->insertObject('test_products', ['idProduct'=>1,'name'=>'Cocacola']);
$pdoOne->insertObject('test_products', ['idProduct'=>2,'name'=>'Fanta']);
// another way to insert values
$pdoOne->set(['idProduct','i',3,'name','s','Sprite'])
->insert('test_products');
}
$button=@$_POST['button'];
if($button) {
// we press the button
$searchText=@$_POST['searchText'];
$result=$pdoOne->select('*')->from('test_products')->where('name like ?',["%$searchText%"])->toList();
if($result===false) {
// result is false if the operation failed.
$result=[];
}
} else {
$searchText='';
$result=$pdoOne->select('*')->from('test_products')->toList();
}
$blade=new BladeOne();
echo $blade->run('list'
,[
'searchText'=>$searchText
,'result'=>$result
,'count'=>count($result)
]);