-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQL.php
147 lines (114 loc) · 3.56 KB
/
SQL.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<h2>IMPOS</h2>
<h2>UPPOS</h2>
<?php
error_reporting(E_ERROR);
// connect to DSN MSSQL with a user and password
$connect = odbc_connect("mssql", "sa", "Password01") or die ("couldn't connect");
//odbc_exec($connect, "use SSDC");
$result = odbc_exec($connect, "select top(5) * from CustomerBasicInf");
//SELECT row_number(1) OVER (ORDER BY Col1 DESC) FROM FROMSISLEY_BAK_WCLAD
//$result = mb_convert_encoding($result, "UTF-8");
odbc_result_all($result);
//odbc_fetch_row($result);
$_customer = array();
$CustomerArr = array();
$max = odbc_num_fields($res);
while(odbc_fetch_row($result)){
$max = odbc_num_fields($res);
odbc_fetch_row($result);
for($i=1;$i<=$max;$i++) {
$_customer[] = odbc_result($result,$i);
}
//print(odbc_result_all($result));
$CustomerArr[] = $_customer;
}
odbc_free_result($result);
odbc_close($connect);
var_dump($max);
?>
___________________________________________
<?php var_dump($CustomerArr); ?>
<?php
/*$customerData = array(
'email' => '[email protected]',
'firstname' => 'asd',
'lastname' => 'asd',
);
function setCustomer($customerData) {
$customer = Mage::getModel('customer/customer')->setId(null);
$customer = Mage::getModel('customer/customer')
->setData($customerData)
->save();
$CustomerId = $customer->getId();
return $CustomerId;
}
*/
?>
<?php
/**
** get all new orders info
/*
$customerData = array(
'email' => '[email protected]',
'firstname' => 'asd',
'lastname' => 'asd',
'password' => '123456',
'id'=>'sdsdad'
);
//生成客户并返回$customerid
function setCustomer($customerData) {
$customer = Mage::getModel('customer/customer')->setId(null);
$customer = Mage::getModel('customer/customer')
->setData($customerData)
->save();
$CustomerId = $customer->getId();
return $CustomerId;
}
//更新已有的客户信息
function updateCustomer($customerData) {
$dbname = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/dbname');
$username = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/username');
$password = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/password');
$posid = $customerData['id'];
$customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addFieldToFilter('posid', $posid);
if (count($customers) > 0) {
$link = mysql_connect('localhost', $username, $password);
if (!$link) {
die('Not connected : ' . mysql_error());
}//end if
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}else{
$query = sprintf("SELECT entity_id FROM customer_entity_varchar WHERE attribute_id ='180' AND value = '%s'",
mysql_real_escape_string($posid));
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}//end if
while ($row = mysql_fetch_assoc($result)) {
$customerId = $row['entity_id'];
}
}
$customer = Mage::getModel('customer/customer')->load($customerId);
foreach ($customerData as $key=>$value) {
$customer->setData($key, $customerData[$key]);
}
$customer->save();
mysql_close($link);
}else{
if ($customerData['email'] != NULL) {
$EleA = 'P'.$posid;
$email = $EleA.'@sisley.com';
$customerData[email] = $email;
}
$customerData[password] = '123123';
$customer = setCustomer($customerData);
}
return $customer;
}
$NewCustomer = updateCustomer($customerData);
*/
?>