Print sql error in PHP

<?php
$con=mysqli_connect(“localhost”,”my_user”,”my_password”,”my_db”);
// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}

// Perform a query, check for error
if (!mysqli_query($con,”INSERT INTO Persons (FirstName) VALUES (‘Glenn’)”))
{
echo(“Error description: ” . mysqli_error($con));
}

mysqli_close($con);
?>

Python Automation GUI3: check a handle available

import WindowGuiAuto
import win32api
def get_handle_object(window_class=None,window_name=None,object_name=None,object_type=None,timeout=200):
EnumChildHandle = []
hwnd = WindowGuiAuto.findTopWindow(wantedText=window_name, wantedClass=window_class)
win32gui.EnumChildWindows(hwnd, all_ok, EnumChildHandle)
for handle in EnumChildHandle:
    if object_type in win32gui.GetClassName(handle):
        if HwndWrapper(handle).Texts()[0] != None:
            if object_name in HwndWrapper(handle).Texts()[0]:
                return True
return False

def all_ok(hwnd, child_handles):
        child_handles.append(hwnd)

Python Automation GUI2: common functions

1.Write to file:

mainfile_path = os.path.join(workspace_path,project_name+‘/src/main.c’)

mainfile = open(mainfile_path,‘w’)

for element in newcontent:

    mainfile.write(element)

mainfile.close()

2. read a file:

          infomation_input = open(log_file, ‘r’).read()

3.Press keys:

yautogui.hotkey(‘ctrl’,‘3’)  # press more than 1 keyboard

yautogui.hotkey(‘ctrl’,‘a’)  # press more than 1 keyboard

pyautogui.press(‘enter’presses 1pause 1) # press one key many times

4.Type text:

pyautogui.typewrite(‘close part’)

5.Clipboard

return_text = clipboard.paste()

6.synchronize button status

swtwindow = app.SWT_Window0

swtwindow.Wait(‘ready’)

toolbarwindow = swtwindow[u’74’]

toolbar_button = toolbarwindow.Button(3)

count = 0;

while toolbar_button.IsEnabled() != True:

    toolbar_button = toolbarwindow.Button(3)

    time.sleep(1)

    count = count+1

    print ‘waiting …%s second’ %count

    if count > 120:

        break

7. check path is a directory or not.

os.path.isdir(os.path.join(workspace_path,‘project2’))

8 Check if file is existing:

if os.path.isfile(‘myfile.txt’):

9. split string 

folder_path = s32ds_path.split(\\eclipse\\s32ds.exe’)[0]

10. Input loop:

inputname = 0

while True and ((inputname < 1or (inputname > len(user))):

    try:

        inputname = int(input(“Please select a User to run ?: “))

    except:

        print(“Please type a integer from 1 to %s !” len(user))

        continue

    else:

        if inputname>= and inputname <= len(user):

            break

            else:

                        print(“Please type a integer from 1 to %s !” len(user))

11. Get all things in folder:

all_sub_file_folder = os.listdir(folder_SDK)

12. print string with format function

    userlist = []

    for item in user:

        count += 1

        userlist.append(‘%s: %s’ % (count, item))

    for i in range(len(userlist)/3):

        test = (userlist[i],userlist[i+len(userlist)/3],userlist[i+2*len(userlist)/3])

        print ‘{0:<20} {1:<20} {2:<20}’.format(*test)

GIT: work as a professional Dev

For example: we have 2 branches:
master
thuan
// from master
git checkout master
git pull (to get latest version)
//step1
// to work with branch “thuan”
git checkout thuan
git merge master //(to update latest from master)
//modified, update, create new scripts, …
git add file1 file1 file2  //(or git rm file1 file2)
git commit -m”Create new scripts file1, file2″
git push origin thuan
// Now your work finished, then you want to push the changes to master branch
//step2
git checkout master
git pull
git merge thuan
// if there is any conflict, please resolve it first
// then add the changes again (if there is conflict)
git add file1 file2
git commit -m”commit the changes”
git push origin master
//Done
// now you wanna changes somethings again, do the step again.