https://wiki.uniformserver.com/index.php?title=MongoDB_Tutorial_3:_Create_database&feed=atom&action=historyMongoDB Tutorial 3: Create database - Revision history2024-03-28T19:03:02ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=MongoDB_Tutorial_3:_Create_database&diff=4334&oldid=prevRic: New page: {{Nav MongoDB Tutorial 3}} '''''Create a database and user''''' == Introduction == Most MySQL administrators will be familiar with creating a restricted user and assigning that user to a s...2010-08-01T13:19:28Z<p>New page: {{Nav MongoDB Tutorial 3}} '''''Create a database and user''''' == Introduction == Most MySQL administrators will be familiar with creating a restricted user and assigning that user to a s...</p>
<p><b>New page</b></p><div>{{Nav MongoDB Tutorial 3}}<br />
'''''Create a database and user'''''<br />
== Introduction ==<br />
Most MySQL administrators will be familiar with creating a restricted user and assigning that user to a specific database. MongDB does things slightly different when a database is first used that database is created on the fly. Selecting a non-existent database and assigning a user creates that database. If database and user exists and password is different the password will be updated.<br />
<br />
On previous page I explained using a multi-purpose function that performs the above. This page covers making that function more accessible by adding a cosmetic windows interface.<br />
<br />
== Template ==<br />
I have provided a windows temple for this tutorial topic save the following to a new file z_mongo\mongodb_1\control \'''''window_create_database.inc.php'''''.<br />
<pre><br />
<?php<br />
<br />
//-- Constants ----------------------------------------------------------------<br />
<br />
define('IDC_USER_NAME', 3010); // Text box New user name<br />
define('IDC_USER_PASSWORD', 3020); // Text box New user password<br />
define('IDC_USER_DATABASE', 3030); // Text box Database name<br />
define('IDC_USER_CANCEL', 3040); // Button Reset to default<br />
define('IDC_USER_CREATE', 3050); // Button Create new user<br />
define('IDC_USER_HELP', 3060); // Help<br />
<br />
define('IDC_USER_LISTBOX', 3070); // Database list box<br />
<br />
// Common variables<br />
<br />
$mongo_user_win; // Window handle<br />
$user_new_db; // List of dbs<br />
<br />
//=== Create function =========================================================<br />
function create_database_window($parent){<br />
global $mongo_user_win;<br />
global $user_new_db;<br />
<br />
//=== 1) Create main window ---------------------------------------------------<br />
<br />
$mongo_user_win = wb_create_window($parent, ModalDialog, "MongoDB Create Databse assign user", WBC_CENTER, WBC_CENTER, 294, 284,<br />
WBC_INVISIBLE | WBC_NOTIFY | WBC_TOP, WBC_HEADERSEL);<br />
<br />
//=== 2) Create controls for the main window ----------------------------------<br />
<br />
wb_create_control($mongo_user_win, Frame, 'User details and db name', 5, 5, 275, 130, 0, 0, 0, 0);<br />
wb_create_control($mongo_user_win, Label, 'User Name', 15, 25, 50, 15, 0, 0, 0, 0);<br />
wb_create_control($mongo_user_win, EditBox, '', 75, 25, 195, 20, IDC_USER_NAME, 0, 0, 0);<br />
wb_create_control($mongo_user_win, Label, 'Password', 15, 50, 45, 15, 0, 0x00000000, 0, 0);<br />
wb_create_control($mongo_user_win, EditBox, '', 75, 50, 195, 20, IDC_USER_PASSWORD, 0, 0, 0);<br />
wb_create_control($mongo_user_win, Label, 'Database', 15, 75, 45, 15, 0, 0x00000000, 0, 0);<br />
wb_create_control($mongo_user_win, EditBox, '', 75, 75, 195, 20, IDC_USER_DATABASE, 0, 0, 0);<br />
wb_create_control($mongo_user_win, PushButton, 'Help', 15, 105, 50, 25, IDC_USER_HELP, 0, 0, 0);<br />
wb_create_control($mongo_user_win, PushButton, 'Create Change', 75, 105, 115, 25, IDC_USER_CREATE, 0, 0, 0);<br />
wb_create_control($mongo_user_win, PushButton, 'Cancel', 200, 105, 70, 25, IDC_USER_CANCEL, 0, 0, 0);<br />
<br />
wb_create_control($mongo_user_win, Frame, 'Select a database', 5, 140, 275, 105, 0, 0x00000000, 0, 0);<br />
$list = wb_create_control($mongo_user_win, ListView, 'Head1', 20, 155, 250, 85, IDC_USER_LISTBOX, 0x00100080, 0, 0);<br />
<br />
<br />
//=== INIT ====================<br />
//--- Set up listview ---<br />
<br />
//=== END INIT ================ <br />
<br />
//=== 3) Assign handler function to the main window --------------------------<br />
wb_set_handler($mongo_user_win, "process_mysql_user");<br />
wb_set_image($mongo_user_win, getcwd()."/images/utray.ico"); // Add logo <br />
wb_set_visible($mongo_user_win, true); // Show window <br />
<br />
//=== 5) Enter application loop -----------------------------------------------<br />
//wb_main_loop(); <br />
<br />
}//==================================================== End Create function ===<br />
<br />
//=== 4) Handler Function -----------------------------------------------------<br />
function process_mysql_user($window, $id, $ctrl=0, $lparam1=0, $lparam2=0){<br />
global $user_new_db;<br />
<br />
switch($id) { <br />
<br />
case IDCLOSE: // Constant IDCLOSE (8) predefined <br />
wb_destroy_window($window); // Destroy the window<br />
break; <br />
}<br />
}<br />
//==================================================== End Handler Function ===<br />
?><br />
</pre><br />
* Template contains unique contatnts for the windows components. Some common variables are defined.<br />
* We are wrapping the pop-up windows in a function create_database_window($parent).<br />
* A modaldialouge window is created invisible this allows it to be populated with data before being displayed.<br />
* Components are added labels, buttons and edit boxes. Only new component is the list view.<br />
* A section is reserved to set-up list view(add titles etc) <br />
* Next section assigns a handler function and logo. With the window completed it is displayed.<br />
* There is no need to run function wb_main_loop() this window is a child.<br />
* Finally the template contains a handler function.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
=== Test ===<br />
Edit file z_mongo\mongodb_1\control\'''''mongo_db.php'''''<br />
Add the following to the include section:<br />
<pre><br />
include_once "window_create_database.inc.php"; // Window create database and assign user<br />
</pre><br />
Change the following section as shown:<br />
<pre><br />
//=== Display help info ====================================================<br />
case ID_HELP_BUTTON: // Button <br />
<br />
create_database_window($window);<br />
// create_port_change_window($window);<br />
// wb_exec('Notepad',INFO_TXT);<br />
<br />
break; <br />
//================================================ END Display help info ===<br />
</pre><br />
{|<br />
|-Valign="top"<br />
|<br />
'''''Run'''''<br />
* Run Run_mongo_db.bat<br />
* Click "Help and Information" button<br />
* Result shown on right <br />
<br />
I mentioned it is cosmetic! Looks pretty with no functionality.<br />
<br />
'''''Note'':'''<br />
* This pop-up requires no separate initialisation function.<br />
* List box can be populated when it is created.<br />
|<br />
[[Image:Mongo_c_initial_5.gif]]<br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
== List view - List databases ==<br />
Add yhe following code<br />
{|<br />
|-<br />
|<br />
<pre><br />
//=== INIT ====================<br />
//--- Set up listview ---<br />
<br />
// Set column titles and widths<br />
wb_set_text($list, array(<br />
array("List of Databases", 200),<br />
));<br />
<br />
$user_new_db = list_dbs_auth(); // Get list of dbs<br />
<br />
// Create rows and columns<br />
wb_create_items($list,$user_new_db); // Fill list<br />
<br />
//--- End Set up listview ---<br />
<br />
//=== END INIT ================ <br />
</pre><br />
|<br />
* The dark header of list view is populated with a column title<br />
* Function wb_set_text requires an handle '''$list''' to the list. This is followed by an array of titles/widths only a single column in this case.<br />
* We obtain an array of databases and save to variable $user_new_db <br />
* This array is used to populate list view using function wb_create_items. It takes as parameters handle $list and the array of dbs <br />
|}<br />
'''''[[#top | Top]]'''''<br />
=== Item Clicked ===<br />
When an item is clicked we want that item to be displayed in the database edit text window.<br />
{|<br />
|-<br />
|<br />
<pre><br />
//=== Item selected from list ==============================================<br />
case IDC_USER_LISTBOX: // A row was selected from db list<br />
<br />
$sel = wb_get_selected($ctrl); // Get selection<br />
$sel = $sel ? implode(", ", $sel) : "none"; // Set selected value <br />
<br />
if($sel =="none"){<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),""); // Reset Set DB<br />
}<br />
else{<br />
<br />
$selected_index = $sel; // Save Array index<br />
$contents = wb_get_text($ctrl); // Get row selected Returns an array of arrays<br />
$first_array = $contents[0]; // Select first array (which is selected row)<br />
$db_selected_name = $first_array[0]; // Select first column (which is db)<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),$db_selected_name); // Set DB<br />
}<br />
break;<br />
//============================================== Item selected from list ===<br />
</pre><br />
|<br />
* Item in list view click this event is passed to the handler function<br />
* List view is detected by a case statement using IDC_USER_LISTBOX<br />
* Either an item or blank item was clicked first we obtain an handle<br />
* This is used to determine what was returned. <br />
* sel is either none or an index<br />
* If "none" set the database list box to blank<br />
* If it was an index save it for later use<br />
* Get select name and set edit box accordingly <br />
|}<br />
'''''[[#top | Top]]'''''<br />
=== User name ===<br />
Selecting a database we want to display the user assigned to it. Every database created will have a single user assigned.<br />
<br />
Well that’s an assumption if more users have been assigned only the first will be displayed. <br />
{|<br />
|-<br />
|<br />
<pre><br />
//=== Item selected from list ==============================================<br />
case IDC_USER_LISTBOX: // A row was selected from db list<br />
<br />
$sel = wb_get_selected($ctrl); // Get selection<br />
$sel = $sel ? implode(", ", $sel) : "none"; // Set selected value <br />
<br />
if($sel =="none"){<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),""); // Reset Set DB<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),""); // Reset User name<br />
}<br />
else{<br />
$selected_index = $sel; // Save Array index<br />
$contents = wb_get_text($ctrl); // Get row selected Returns an array of arrays<br />
$first_array = $contents[0]; // Select first array (which is selected row)<br />
$db_selected_name = $first_array[0]; // Select first column (which is db)<br />
$db_selected_name = trim($db_selected_name); // Clean<br />
<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),$db_selected_name); // Set DB<br />
<br />
$users_array = get_user_auth($db_selected_name); //Select db return user/s in array<br />
<br />
if(empty($users_array)){ // No users<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),""); // Reset User name<br />
}<br />
else{ // Selet first user and display<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),$users_array[0]); // Set User name<br />
}<br />
}<br />
break;<br />
//============================================== Item selected from list ===<br />
</pre><br />
|<br />
* When a user clicks a database its name is stored in variable $db_selected_name<br />
* This is used to obtain an array of users using function get_user_auth($db_selected_name)<br />
* Returned array is saved in variable $users_array<br />
** If empty reset user name edit box<br />
** Not empty pick first user from array and display in edit box.<br />
* End case <br />
|}<br />
'''''[[#top | Top]]'''''<br />
<br />
=== Cancel ===<br />
Cancel button is provided as a quick way to restore window to its initial state. <br />
{|<br />
|-<br />
|<br />
<pre><br />
//=== CANCEL ===============================================================<br />
// Restore defaults<br />
<br />
case IDC_USER_CANCEL: <br />
<br />
//-- Reset text boxes<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),""); // Clear name<br />
wb_set_text(wb_get_control($window, IDC_USER_PASSWORD),""); // Clear password<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),""); // Clear DB<br />
<br />
<br />
//--- Reset selected list box<br />
$temp = $user_new_db; // Save old array <br />
wb_delete_items (wb_get_control($window, IDC_USER_LISTBOX),NULL); // Delete all list view entries<br />
wb_create_items (wb_get_control($window, IDC_USER_LISTBOX),$temp); // Add array<br />
<br />
break;<br />
//============================================================ END CANCEL ===<br />
</pre><br />
|<br />
* All edit boxes are cleared<br />
* List array is set to NULL clearing all list entries<br />
* Original array is restored<br />
|}<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Create database or update password ==<br />
Button '''Create or Update''' reads the text fields and validates each one. On validation creates a new database or updates a user password. List of databases is refreshed.<br />
{|<br />
|-<br />
|<br />
<pre><br />
//=== CREATE DATABASE ASIGN USER ============================================<br />
case IDC_USER_CREATE: <br />
<br />
$name = wb_get_text(wb_get_control($window, IDC_USER_NAME)); // Get name<br />
$pass = wb_get_text(wb_get_control($window, IDC_USER_PASSWORD)); // Get pass<br />
$db = wb_get_text(wb_get_control($window, IDC_USER_DATABASE));// Get db<br />
<br />
// Validate - name alphanumeric<br />
if (!(preg_match("/^[A-Za-z0-9_]+$/", $name ))) {<br />
$str = "";<br />
$str .= "If name is empty please enter a name\n";<br />
$str .= "Only alphanumeric characters allowed";<br />
wb_message_box($window, $str,"User Name", WBC_INFO); <br />
break;<br />
}<br />
<br />
// Validate password - require six or more alphanumeric characters<br />
if (!(preg_match("/^[A-Za-z0-9_]{6,}$/", $pass))) {<br />
$str = "";<br />
$str .= "If password is empty please enter a password\n";<br />
$str .= "Enter six or more alphanumeric characters\n";<br />
$str .= "Only alphanumeric characters allowed";<br />
wb_message_box($window, $str,"Password", WBC_INFO); <br />
break;<br />
}<br />
<br />
// Validate - db name <br />
if (!(preg_match("/^[A-Za-z0-9_]+$/", $db))) {<br />
$str = "";<br />
$str .= "If name is empty please enter a name\n";<br />
$str .= "Only alphanumeric characters allowed";<br />
wb_message_box($window, $str,"DB Name", WBC_INFO); <br />
break;<br />
}<br />
<br />
// Create database or update user password<br />
create_db_auth($db,$name,$pass); <br />
<br />
// Refresh database list<br />
$user_new_db = list_dbs_auth(); // Get list of dbs<br />
$temp = $user_new_db; <br />
wb_delete_items (wb_get_control($window, IDC_USER_LISTBOX),NULL); <br />
wb_create_items (wb_get_control($window, IDC_USER_LISTBOX),$temp); <br />
<br />
break;<br />
//======================================= END CREATE DATABASE ASIGN USER ===<br />
</pre><br />
|<br />
* All three-text fields are read into variables $db,$name and $pass<br />
* Each is checked against a list of valid characters.<br />
** Note: You can add to this list of valid characters<br />
** Password is forced to have a minimum of six characters<br />
* With all three fields validated either a new database is created or user password updated.<br />
* List of databases is refreshed.<br />
<br />
|} <br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Can script be run ==<br />
{|<br />
|-valign="top"<br />
|<br />
At this stage we have not decided how to run this script. There are two options either from a drop down menu or using a button on main application.<br />
<br />
Script requires MongoDB server to be running, we can prevent the script from being called by disabling a button. However this is not possible with a drop down menu hence we need to include a check and alert a user accordingly.<br />
|<br />
<pre><br />
// Check server running<br />
if(!mongodb_running()){<br />
$str = "";<br />
$str .= "This item requires access to a running server.\n";<br />
$str .= "Please start MonGoDB server and run\n";<br />
$str .= "this item again.";<br />
wb_message_box(NULL, $str,"Server not running", WBC_INFO); <br />
return; // Give up<br />
}<br />
</pre><br />
|}<br />
'''''[[#top | Top]]'''''<br />
== Complete Script ==<br />
<pre><br />
<?php<br />
<br />
//-- Constants ----------------------------------------------------------------<br />
<br />
define('IDC_USER_NAME', 3010); // Text box New user name<br />
define('IDC_USER_PASSWORD', 3020); // Text box New user password<br />
define('IDC_USER_DATABASE', 3030); // Text box Database name<br />
define('IDC_USER_CANCEL', 3040); // Button Reset to default<br />
define('IDC_USER_CREATE', 3050); // Button Create new user<br />
define('IDC_USER_HELP', 3060); // Help<br />
<br />
<br />
define('IDC_USER_LISTBOX', 3070); // Database list box<br />
<br />
// Common variables<br />
<br />
$mongo_user_win; // Window handle<br />
$user_new_db; // List of dbs<br />
<br />
//=== Create function =========================================================<br />
function create_database_window($parent){<br />
global $mongo_user_win;<br />
global $user_new_db;<br />
<br />
// Check server running<br />
if(!mongodb_running()){<br />
$str = "";<br />
$str .= "This item requires access to a running server.\n";<br />
$str .= "Please start MonGoDB server and run\n";<br />
$str .= "this item again.";<br />
wb_message_box(NULL, $str,"Server not running", WBC_INFO); <br />
return; // Give up<br />
}<br />
<br />
//=== 1) Create main window ---------------------------------------------------<br />
<br />
$mongo_user_win = wb_create_window($parent, ModalDialog, "MongoDB Create Databse assign user", WBC_CENTER, WBC_CENTER, 294, 284,<br />
WBC_INVISIBLE | WBC_NOTIFY | WBC_TOP, WBC_HEADERSEL);<br />
<br />
//=== 2) Create controls for the main window ----------------------------------<br />
<br />
wb_create_control($mongo_user_win, Frame, 'User details and db name', 5, 5, 275, 130, 0, 0, 0, 0);<br />
wb_create_control($mongo_user_win, Label, 'User Name', 15, 25, 50, 15, 0, 0, 0, 0);<br />
wb_create_control($mongo_user_win, EditBox, '', 75, 25, 195, 20, IDC_USER_NAME, 0, 0, 0);<br />
wb_create_control($mongo_user_win, Label, 'Password', 15, 50, 45, 15, 0, 0x00000000, 0, 0);<br />
wb_create_control($mongo_user_win, EditBox, '', 75, 50, 195, 20, IDC_USER_PASSWORD, 0, 0, 0);<br />
wb_create_control($mongo_user_win, Label, 'Database', 15, 75, 45, 15, 0, 0x00000000, 0, 0);<br />
wb_create_control($mongo_user_win, EditBox, '', 75, 75, 195, 20, IDC_USER_DATABASE, 0, 0, 0);<br />
wb_create_control($mongo_user_win, PushButton, 'Help', 15, 105, 50, 25, IDC_USER_HELP, 0, 0, 0);<br />
wb_create_control($mongo_user_win, PushButton, 'Create or Change', 75, 105, 115, 25, IDC_USER_CREATE, 0, 0, 0);<br />
wb_create_control($mongo_user_win, PushButton, 'Cancel', 200, 105, 70, 25, IDC_USER_CANCEL, 0, 0, 0);<br />
<br />
wb_create_control($mongo_user_win, Frame, 'Select a database', 5, 140, 275, 105, 0, 0x00000000, 0, 0);<br />
$list = wb_create_control($mongo_user_win, ListView, 'Head1', 20, 155, 250, 85, IDC_USER_LISTBOX, 0x00100080, 0, 0);<br />
<br />
<br />
//=== INIT ====================<br />
//--- Set up listview ---<br />
<br />
// Set column titles and widths<br />
wb_set_text($list, array(<br />
array("List of Databases", 200),<br />
));<br />
<br />
$user_new_db = list_dbs_auth(); // Get list of dbs<br />
<br />
// Create rows and columns<br />
wb_create_items($list,$user_new_db); // Fill list<br />
<br />
//--- End Set up listview ---<br />
<br />
//=== END INIT ================ <br />
<br />
//=== 3) Assign handler function to the main window --------------------------<br />
wb_set_handler($mongo_user_win, "process_mysql_user");<br />
wb_set_image($mongo_user_win, getcwd()."/images/utray.ico"); // Add logo <br />
wb_set_visible($mongo_user_win, true); // Show window <br />
<br />
//=== 5) Enter application loop -----------------------------------------------<br />
//wb_main_loop(); <br />
<br />
}//==================================================== End Create function ===<br />
<br />
//=== 4) Handler Function -----------------------------------------------------<br />
function process_mysql_user($window, $id, $ctrl=0, $lparam1=0, $lparam2=0){<br />
global $user_new_db;<br />
<br />
switch($id) { <br />
<br />
//=== CREATE DATABASE ASIGN USER ============================================<br />
case IDC_USER_CREATE: <br />
<br />
$name = wb_get_text(wb_get_control($window, IDC_USER_NAME)); // Get name<br />
$pass = wb_get_text(wb_get_control($window, IDC_USER_PASSWORD)); // Get pass<br />
$db = wb_get_text(wb_get_control($window, IDC_USER_DATABASE));// Get db<br />
<br />
// Validate - name alphanumeric<br />
if (!(preg_match("/^[A-Za-z0-9_]+$/", $name ))) {<br />
$str = "";<br />
$str .= "If name is empty please enter a name\n";<br />
$str .= "Only alphanumeric characters allowed";<br />
wb_message_box($window, $str,"User Name", WBC_INFO); <br />
break;<br />
}<br />
<br />
// Validate password - require six or more alphanumeric characters<br />
if (!(preg_match("/^[A-Za-z0-9_]{6,}$/", $pass))) {<br />
$str = "";<br />
$str .= "If password is empty please enter a password\n";<br />
$str .= "Enter six or more alphanumeric characters\n";<br />
$str .= "Only alphanumeric characters allowed";<br />
wb_message_box($window, $str,"Password", WBC_INFO); <br />
break;<br />
}<br />
<br />
// Validate - db name <br />
if (!(preg_match("/^[A-Za-z0-9_]+$/", $db))) {<br />
$str = "";<br />
$str .= "If name is empty please enter a name\n";<br />
$str .= "Only alphanumeric characters allowed";<br />
wb_message_box($window, $str,"DB Name", WBC_INFO); <br />
break;<br />
}<br />
<br />
// Create database or update user password<br />
create_db_auth($db,$name,$pass); <br />
<br />
// Refresh database list<br />
$user_new_db = list_dbs_auth(); // Get list of dbs<br />
$temp = $user_new_db; // Save array <br />
wb_delete_items (wb_get_control($window, IDC_USER_LISTBOX),NULL); // Delete all list view entries<br />
wb_create_items (wb_get_control($window, IDC_USER_LISTBOX),$temp); // Add array<br />
<br />
break;<br />
//======================================= END CREATE DATABASE ASIGN USER ===<br />
<br />
<br />
//=== CANCEL ===============================================================<br />
// Restore defaults<br />
<br />
case IDC_USER_CANCEL: <br />
<br />
//-- Reset text boxes<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),""); // Clear name<br />
wb_set_text(wb_get_control($window, IDC_USER_PASSWORD),""); // Clear password<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),""); // Clear DB<br />
<br />
<br />
//--- Reset selected list box<br />
$temp = $user_new_db; // Save old array <br />
wb_delete_items (wb_get_control($window, IDC_USER_LISTBOX),NULL); // Delete all list view entries<br />
wb_create_items (wb_get_control($window, IDC_USER_LISTBOX),$temp); // Add array<br />
<br />
break;<br />
//============================================================ END CANCEL ===<br />
<br />
//=== Item selected from list ==============================================<br />
case IDC_USER_LISTBOX: // A row was selected from db list<br />
<br />
$sel = wb_get_selected($ctrl); // Get selection<br />
$sel = $sel ? implode(", ", $sel) : "none"; // Set selected value <br />
<br />
if($sel =="none"){<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),""); // Reset Set DB<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),""); // Reset User name<br />
}<br />
else{<br />
$selected_index = $sel; // Save Array index<br />
$contents = wb_get_text($ctrl); // Get row selected Returns an array of arrays<br />
$first_array = $contents[0]; // Select first array (which is selected row)<br />
$db_selected_name = $first_array[0]; // Select first column (which is db)<br />
$db_selected_name = trim($db_selected_name); // Clean<br />
<br />
wb_set_text(wb_get_control($window, IDC_USER_DATABASE),$db_selected_name); // Set DB<br />
<br />
$users_array = get_user_auth($db_selected_name); //Select db return user/s in array<br />
<br />
if(empty($users_array)){ // No users<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),""); // Reset User name<br />
}<br />
else{ // Selet first user and display<br />
wb_set_text(wb_get_control($window, IDC_USER_NAME),$users_array[0]); // Set User name<br />
}<br />
}<br />
break;<br />
//============================================== Item selected from list ===<br />
<br />
<br />
case IDCLOSE: // Constant IDCLOSE (8) predefined <br />
wb_destroy_window($window); // Destroy the window<br />
break; <br />
}<br />
}<br />
//==================================================== End Handler Function ===<br />
?><br />
</pre><br />
'''''[[#top | Top]]'''''<br />
== Summary ==<br />
That completes this pop-up we can now create databses and update user passwords.<br />
<br />
Next page covers deleting a database [[MongoDB Tutorial 3: Drop database | '''Drop database''']]<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
----<br />
<br />
[[Category: Tutorials]]<br />
[[Category: How To]]<br />
[[Category: Uniform Server 6-Carbo]]</div>Ric