Some code bugs are fixed, connection object was included. Thanks PHP.net for notes