@@ -52,8 +52,7 @@ class db
5252 private $ dbClientFlags = 0 ; // MySQL Client falgs
5353 /**#@-*/
5454
55- public $ show_error_messages = false ; // false in server, true in interface
56-
55+ public $ show_error_messages = false ; // false in server, interface sets true when generating templates
5756
5857 /* old things - unused now ////
5958 private $linkId = 0; // last result of mysqli_connect()
@@ -80,7 +79,7 @@ public function __construct($host = NULL , $user = NULL, $pass = NULL, $database
8079 $ this ->dbUser = $ user ? $ user : $ conf ['db_user ' ];
8180 $ this ->dbPass = $ pass ? $ pass : $ conf ['db_password ' ];
8281 $ this ->dbCharset = $ conf ['db_charset ' ];
83- $ this ->dbClientFlags = $ flags ? $ flags : $ conf ['db_client_flags ' ];
82+ $ this ->dbClientFlags = ( $ flags !== NULL ) ? $ flags : $ conf ['db_client_flags ' ];
8483 $ this ->_iConnId = mysqli_init ();
8584
8685 mysqli_real_connect ($ this ->_iConnId , $ this ->dbHost , $ this ->dbUser , $ this ->dbPass , '' , (int )$ this ->dbPort , NULL , $ this ->dbClientFlags );
@@ -117,6 +116,18 @@ public function close() {
117116 $ this ->_iConnId = null ;
118117 }
119118
119+ /*
120+ * Test mysql connection.
121+ *
122+ * @return boolean returns true if db connection is good.
123+ */
124+ public function testConnection () {
125+ if (mysqli_connect_errno ()) {
126+ return false ;
127+ }
128+ return (boolean )(is_object ($ this ->_iConnId ) && mysqli_ping ($ this ->_iConnId ));
129+ }
130+
120131 /* This allows our private variables to be "read" out side of the class */
121132 public function __get ($ var ) {
122133 return isset ($ this ->$ var ) ? $ this ->$ var : NULL ;
@@ -435,13 +446,14 @@ public function query_all_array($sQuery = '') {
435446 * @return int id of last inserted row or 0 if none
436447 */
437448 public function insert_id () {
438- $ iRes = mysqli_query ($ this ->_iConnId , 'SELECT LAST_INSERT_ID() as `newid` ' );
439- if (!is_object ($ iRes )) return false ;
440-
441- $ aReturn = mysqli_fetch_assoc ($ iRes );
442- mysqli_free_result ($ iRes );
443-
444- return $ aReturn ['newid ' ];
449+ $ oResult = $ this ->query ('SELECT LAST_INSERT_ID() as `newid` ' );
450+ if (!$ oResult ) {
451+ $ this ->_sqlerror ('Unable to select last_insert_id() ' );
452+ return false ;
453+ }
454+ $ aReturn = $ oResult ->get ();
455+ $ oResult ->free ();
456+ return isset ($ aReturn ['newid ' ]) ? $ aReturn ['newid ' ] : 0 ;
445457 }
446458
447459
0 commit comments