33/**
44 * \file
55 * \brief Create / Edit database connection
6- *
6+ *
77 * Call: database_wizard.php
8- *
8+ *
99 * PHP version 8.1
10- *
10+ *
1111 * @category User_Interface
1212 * @package Lwt
1313 * @author HugoFara <hugo.farajallah@protonmail.com>
2222
2323/**
2424 * A connection to database stored as an object.
25- *
25+ *
2626 * @category Database
2727 * @package Lwt
2828 * @author HugoFara <hugo.farajallah@protonmail.com>
@@ -54,15 +54,19 @@ class Database_Connection
5454
5555 /**
5656 * Build a new connection object.
57- *
57+ *
5858 * @param string $server Server name
5959 * @param string $userid User ID
6060 * @param string $passwd Password for this user
6161 * @param string $dbname Database name
6262 * @param string $socket Socket to use
6363 */
64- function __construct (
65- $ server = "" , $ userid = "" , $ passwd = "" , $ dbname = "" , $ socket = ""
64+ public function __construct (
65+ $ server = "" ,
66+ $ userid = "" ,
67+ $ passwd = "" ,
68+ $ dbname = "" ,
69+ $ socket = ""
6670 ) {
6771 $ this ->server = $ server ;
6872 $ this ->userid = $ userid ;
@@ -73,11 +77,11 @@ function __construct(
7377
7478 /**
7579 * Load data from a PHP file.
76- *
80+ *
7781 * The file is usually connect.inc.php or equivalent.
78- *
82+ *
7983 * @param string $file_name PHP file to load data from.
80- *
84+ *
8185 * @return void
8286 */
8387 public function loadFile (string $ file_name )
@@ -118,9 +122,9 @@ public function getAsText(): string
118122
119123/**
120124 * Save the connection to the file connect.inc.php.
121- *
125+ *
122126 * @param Database_Connection $conn Connection object.
123- *
127+ *
124128 * @return void
125129 */
126130function writeToFile ($ conn )
@@ -132,9 +136,9 @@ function writeToFile($conn)
132136
133137/**
134138 * Execute operation.
135- *
139+ *
136140 * @param string $op Operation to execute.
137- *
141+ *
138142 * @return void
139143 */
140144function doOperation ($ op )
@@ -151,8 +155,8 @@ function doOperation($op)
151155 $ passwd = "" ;
152156 $ dbname = (string ) $ _SERVER ['SERVER_NAME ' ];
153157 $ socket = "" ;
154- } else if ($ op == "Check " ) {
155- $ server = getreq ("server " );
158+ } elseif ($ op == "Check " ) {
159+ $ server = getreq ("server " );
156160 $ userid = getreq ("userid " );
157161 $ passwd = getreq ("passwd " );
158162 $ dbname = getreq ("dbname " );
@@ -164,18 +168,26 @@ function doOperation($op)
164168 try {
165169 if ($ socket != "" ) {
166170 $ success = mysqli_real_connect (
167- $ conn , $ server , $ userid , $ passwd , $ dbname ,
171+ $ conn ,
172+ $ server ,
173+ $ userid ,
174+ $ passwd ,
175+ $ dbname ,
168176 socket: $ socket
169177 );
170178 } else {
171179 $ success = mysqli_real_connect (
172- $ conn , $ server , $ userid , $ passwd , $ dbname
180+ $ conn ,
181+ $ server ,
182+ $ userid ,
183+ $ passwd ,
184+ $ dbname
173185 );
174186 }
175187 if (!$ success ) {
176188 $ message = "Can't connect! " ;
177- } else if (mysqli_errno ($ conn ) != 0 ) {
178- $ message = "ERROR: " . mysqli_error ($ conn ) .
189+ } elseif (mysqli_errno ($ conn ) != 0 ) {
190+ $ message = "ERROR: " . mysqli_error ($ conn ) .
179191 " error number: " . mysqli_errno ($ conn );
180192 } else {
181193 $ message = "Connection established with success! " ;
@@ -184,15 +196,19 @@ function doOperation($op)
184196 $ message = (string )$ exept ;
185197 }
186198 }
187- } else if ($ op == "Change " ) {
188- $ server = getreq ("server " );
199+ } elseif ($ op == "Change " ) {
200+ $ server = getreq ("server " );
189201 $ userid = getreq ("userid " );
190202 $ passwd = getreq ("passwd " );
191203 $ dbname = getreq ("dbname " );
192204 $ socket = getreq ("socket " );
193205 }
194206 $ conn = new Database_Connection (
195- $ server , $ userid , $ passwd , $ dbname , $ socket
207+ $ server ,
208+ $ userid ,
209+ $ passwd ,
210+ $ dbname ,
211+ $ socket
196212 );
197213 if ($ op == "Change " ) {
198214 writeToFile ($ conn );
@@ -202,13 +218,13 @@ function doOperation($op)
202218
203219/**
204220 * Generate a form to edit the connection.
205- *
221+ *
206222 * @param Database_Connection $conn Database connection object
207223 * @param string|null $error_message Error message to display
208- *
224+ *
209225 * @return void
210226 */
211- function displayForm ($ conn , $ error_message= null )
227+ function displayForm ($ conn , $ error_message = null )
212228{
213229 pagestart_kernel_nobody ("Database Connection Wizard " );
214230 if ($ error_message != null ) {
@@ -257,7 +273,7 @@ function displayForm($conn, $error_message=null)
257273
258274/**
259275 * Display the main form, filled with data from an existing connection file.
260- *
276+ *
261277 * @return void
262278 */
263279function editConnection ()
@@ -270,7 +286,7 @@ function editConnection()
270286
271287/**
272288 * Display the main form blank.
273- *
289+ *
274290 * @return void
275291 */
276292function createNewConnection ()
@@ -280,7 +296,7 @@ function createNewConnection()
280296
281297if (getreq ('op ' ) != '' ) {
282298 doOperation (getreq ('op ' ));
283- } else if (file_exists ('connect.inc.php ' )) {
299+ } elseif (file_exists ('connect.inc.php ' )) {
284300 editConnection ();
285301} else {
286302 createNewConnection ();
0 commit comments