/var/www/enzatesting.onesolution.hk/~test/connect.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

$dsn         
"sqlsrv:Server=192.168.155.12;Database=enzadb";
$user         'enzasa';
$password     'enza';


$dsn         "sqlsrv:Server=localhost,1433;Database=enzadb_new";
$user         'enzasa';
$password     'enzasq1';
$dbh        null;

try {
    
$options = array(
        
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
    ); 

    
$dbh = new PDO($dsn$user$password$options);

    
//$dbh = mssql_connect($dsn, $user, $password);
    
} catch (PDOException $e) {
    
//send email report to system admin
    
$headers    'From: '.ADMIN_EMAIL."\r\n";
    
$subject    "[ENZA]Could not connect to DB";
    
$msg        'Connection failed: ' $e->getMessage();    
    
mail(ADMIN_EMAIL$subject$msg$headers);
    
    
//header("Location: ".ERROR_PAGE);
    
echo $e;
    exit;
}
$dbh->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND"SET NAMES 'utf8'");
//$dbh -> exec("set names utf8");
$dbh->query("SET NAMES 'utf8'"); ?>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tablelist">
                  <tr>
                        <th>ITEMNO</th>
                        <th>ITEMNAME</th>
                        <th>ITEMGP</th>
                        <th>ITEMTYPE</th>
                        <th>VERIFIED</th>
                        <!--<th>Delete</th>-->
                    </tr>
<?php
//var_dump($_REQUEST);

    
$sql "SELECT
inv_material.*,
itemgp.codedesc_en AS group_en,
itemgp.codedesc_sc AS group_sc,
mattype.codedesc_en AS type_en,
mattype.codedesc_sc AS type_sc,
mattype.codeid,
verified.codedesc_en AS verified_en,
verified.codedesc_sc AS verified_sc

FROM
inv_material
INNER JOIN master_type_code AS itemgp ON itemgp.codeid = inv_material.itemgp
INNER JOIN master_type_code AS mattype ON mattype.codeid = inv_material.mattype
INNER JOIN master_type_code AS verified ON verified.codeid = inv_material.verified
WHERE
itemgp.typeid = 'ITEMGP' AND
verified.typeid = 'VERIFIED' AND
mattype.typeid = 'MATTYPE'
ORDER BY
itemno ASC"
;        
//echo $sql;    

    
$sth $dbh->prepare($sql);
    
$sth->execute(  );
                            
    while(
$row $sth->fetch()) {
        if(empty(
$refid)) $refid $row['refid'];    //default select the first item
        
?>
                  <tr>
                    <td><a href="inv_material_modifyform.php?refid=<?=$row['refid']?>"><?=$row['itemno']?></a></td>
                    <td><?=$row['name_en']?></td>
                    <td><?=$row['group_en']?></td>
                    <td><?=$row['type_en']?></td>
                    <td><?=$row['verified_en']?></td>
                  </tr>
<?php ?>
                </table>