Skip to content

Commit 448f3df

Browse files
committed
2017.02.21. psp_2.1.0
- new library : sd_spc.php - sd_340.php > TxDE flow control support - sn_esmtp.php > auth comparison order change : PLAIN/LOGIN => LOGIN/PLAIN - sn_mysql.php > change default tcp/udp id : 0 => 4 > change default timeout : 5 => 6 seconds > change argument and return value : mysql_error(), mysql_errno() > add return logic from server : mysql_ping(), mysql_select_db() > minor bug fixes - sn_tcp_ac.php > tcp reconnect bug fix
1 parent 97d8576 commit 448f3df

File tree

8 files changed

+666
-225
lines changed

8 files changed

+666
-225
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHPoC source codes for basic libraries and examples
88
* sd_104.php
99
* sd_204.php
1010
* sd_340.php
11+
* sd_spc.php (*NEW*)
1112
* sn_dns.php
1213
* sn_esmtp.php
1314
* sn_mysql.php

example/net/01.php_task/mysql_insert/task0.php

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
include_once "/lib/sn_dns.php";
77
include_once "/lib/sn_mysql.php";
88

9-
//Check and print error messages from DB server
10-
function chk_error($result)
11-
{
12-
if($result !== false)
13-
{
14-
$error = mysql_error($result);
15-
if(strlen($error) != 0)
16-
echo "Error: $error\r\n";
17-
}
18-
}
19-
209
echo "PHPoC example: insert data to MYSQL DB\r\n\r\n";
2110

2211
//Enter your DB Server's hostname or IP address!
@@ -26,39 +15,45 @@ function chk_error($result)
2615
$user_name = "user_id";
2716
$password = "password";
2817

29-
//mysql_setup(0, 0, "", true); // enable IPv6
30-
3118
//Connect to DB Server
32-
if(mysql_connect($server_addr, $user_name, $password))
19+
if(mysql_connect($server_addr, $user_name, $password) === false)
20+
exit(mysql_error());
21+
22+
//Create a database named student
23+
if(mysql_query("CREATE DATABASE student;") === false)
24+
exit(mysql_error());
25+
26+
if(mysql_select_db("student") === false)
27+
exit(mysql_error());
28+
29+
//Create a table named student
30+
if(mysql_query("CREATE TABLE tbl_student (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(20) NOT NULL);") === false)
31+
exit(mysql_error());
32+
33+
//Insert a record
34+
if(mysql_query("INSERT INTO tbl_student (id, name) VALUES (1, 'John');") === false)
35+
exit(mysql_error());
36+
37+
//Inquiry all record
38+
$result = mysql_query("SELECT * FROM tbl_student;");
39+
if($result === false)
40+
exit(mysql_error());
41+
else
3342
{
34-
//Create a database named student
35-
$result = mysql_query("CREATE DATABASE student;");
36-
chk_error($result);
37-
$result = mysql_select_db("student");
38-
chk_error($result);
39-
//Create a table named student
40-
$result = mysql_query("CREATE TABLE tbl_student (id INTEGER, name VARCHAR(20));");
41-
chk_error($result);
42-
//Insert a record
43-
$result = mysql_query("INSERT INTO tbl_student (id, name) VALUES (1, 'John');");
44-
chk_error($result);
45-
//Inquiry all record
46-
$result = mysql_query("SELECT * FROM tbl_student;");
47-
chk_error($result);
48-
//Get a result of the inquiry
4943
$result_arr = mysql_fetch_row($result);
5044
//Print the result
5145
printf("%s -> %s\r\n", $result_arr[0], $result_arr[1]);
52-
//Delete the table
53-
$result = mysql_query("DROP TABLE tbl_student;");
54-
chk_error($result);
55-
//Delete the database
56-
$result = mysql_query("DROP DATABASE student;");
57-
chk_error($result);
58-
echo "example has been finished!\r\n";
59-
mysql_close();
6046
}
61-
else
62-
echo "example has been failed\r\n";
47+
48+
//Delete the table
49+
if(mysql_query("DROP TABLE tbl_student;") === false)
50+
exit(mysql_error());
51+
52+
//Delete the database
53+
if(mysql_query("DROP DATABASE student;") === false)
54+
exit(mysql_error());
55+
56+
mysql_close();
57+
echo "example has been finished!\r\n";
6358

6459
?>

example/net/01.php_task/mysql_update/task0.php

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
include_once "/lib/sn_dns.php";
77
include_once "/lib/sn_mysql.php";
88

9-
//Check and print error messages from DB server
10-
function chk_error($result)
11-
{
12-
if($result !== false)
13-
{
14-
$error = mysql_error($result);
15-
if(strlen($error) != 0)
16-
echo "Error: $error\r\n";
17-
}
18-
}
19-
209
echo "PHPoC example: update data to MYSQL DB\r\n\r\n";
2110

2211
//Enter your DB Server's hostname or IP address!
@@ -26,43 +15,50 @@ function chk_error($result)
2615
$user_name = "user_id";
2716
$password = "password";
2817

29-
//mysql_setup(0, 0, "", true); // enable IPv6
30-
3118
//Connect to DB Server
32-
if(mysql_connect($server_addr, $user_name, $password))
19+
if(mysql_connect($server_addr, $user_name, $password) === false)
20+
exit(mysql_error());
21+
22+
//Create a database named student
23+
if(mysql_query("CREATE DATABASE student;") === false)
24+
exit(mysql_error());
25+
26+
if(mysql_select_db("student") === false)
27+
exit(mysql_error());
28+
29+
//Create a table named student
30+
if(mysql_query("CREATE TABLE tbl_student (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(20) NOT NULL);") === false)
31+
exit(mysql_error());
32+
33+
//Insert a record
34+
if(mysql_query("INSERT INTO tbl_student (id, name) VALUES (1, 'John');") === false)
35+
exit(mysql_error());
36+
37+
//Update the record (John -> Roy)
38+
if(mysql_query("UPDATE tbl_student SET name='Roy' where id=1;") === false)
39+
exit(mysql_error());
40+
41+
//Inquiry all record
42+
$result = mysql_query("SELECT * FROM tbl_student;");
43+
if($result === false)
44+
exit(mysql_error());
45+
else
3346
{
34-
//Create a database named student
35-
$result = mysql_query("CREATE DATABASE student;");
36-
chk_error($result);
37-
$result = mysql_select_db("student");
38-
chk_error($result);
39-
//Create a table named student
40-
$result = mysql_query("CREATE TABLE tbl_student (id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(20) NOT NULL);");
41-
chk_error($result);
42-
//Insert a record
43-
$result = mysql_query("INSERT INTO tbl_student (id, name) VALUES (1, 'John');");
44-
chk_error($result);
45-
//Update the record (John -> Roy)
46-
$result = mysql_query("UPDATE tbl_student SET name='Roy' where id=1;");
47-
chk_error($result);
48-
//Inquiry all record
49-
$result = mysql_query("SELECT * FROM tbl_student;");
50-
chk_error($result);
51-
//Get a result of the inquiry
5247
$result_arr = mysql_fetch_row($result);
5348
//Print the result
5449
printf("%s -> %s\r\n", $result_arr[0], $result_arr[1]);
55-
//Delete the table
56-
$result = mysql_query("DROP TABLE tbl_student;");
57-
chk_error($result);
58-
//Delete the database
59-
$result = mysql_query("DROP DATABASE student;");
60-
chk_error($result);
61-
echo "example has been finished!\r\n";
62-
mysql_close();
6350
}
64-
else
65-
echo "example has been failed\r\n";
51+
52+
//Delete the table
53+
if(mysql_query("DROP TABLE tbl_student;") === false)
54+
exit(mysql_error());
55+
56+
//Delete the database
57+
if(mysql_query("DROP DATABASE student;") === false)
58+
exit(mysql_error());
59+
60+
mysql_close();
61+
echo "example has been finished!\r\n";
6662

6763
?>
6864

lib/sd_340.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
// $psp_id sd_340.php date 20160519
3+
// $psp_id sd_340.php date 20170214
44
// P4S-340/342 basic library
55

66
define("LOW", 0);
@@ -226,6 +226,9 @@ function uart_setup($uart_id, $baud, $set = "N81N")
226226
case "S": /* S/W flow control */
227227
$flowctrl = 2;
228228
break;
229+
case "T": /* TxDE flow control */
230+
$flowctrl = 3;
231+
break;
229232
default:
230233
exit("uart_setup: invalid flow control $flowctrl\r\n");
231234
break;

0 commit comments

Comments
 (0)