--- /home/mtolmacs/Projects/Personal/Quercus-3.2.1/src/com/caucho/quercus/lib/db/Mysqli.java	2009-01-27 22:42:03.000000000 +0100
+++ /home/mtolmacs/Projects/Personal/BladeRunner/src/com/caucho/quercus/lib/db/Mysqli.java	2009-01-28 13:53:09.000000000 +0100
@@ -217,8 +217,15 @@ public class Mysqli extends JdbcConnecti
       return jConn;
     } catch (SQLException e) {
       env.warning(L.l("A link to the server could not be established.\n  url={0}\n  driver={1}\n  {2}", url, driver, e.toString()), e);
-
-      env.setSpecialValue("mysqli.connectErrno", new LongValue(e.getErrorCode()));
+      
+      // Provide an arbitrary (non-zero) error code even when the vendor error code is zero
+      // Zero should never be returned as mysql_errno and mysqli_errno returns != 0
+      // when error happened and 0 when everything was okay
+      int errorCode = e.getErrorCode();
+      if (errorCode == 0)
+    	  errorCode = 20000;
+      
+      env.setSpecialValue("mysqli.connectErrno", new LongValue(errorCode));
       env.setSpecialValue("mysqli.connectError", env.createString(e.getMessage()));
 
       return null;
