@@ -138,25 +138,26 @@ public function parse($data)
138
138
$ this ->state = self ::STATE_STANDBY ;
139
139
//$this->stream->bufferSize = 4;
140
140
if ($ this ->phase === 0 ) {
141
- $ this ->phase = self ::PHASE_GOT_INIT ;
142
- $ this ->protocalVersion = $ this ->buffer ->readInt1 ();
143
- $ this ->debug (sprintf ("Protocal Version: %d " , $ this ->protocalVersion ));
144
- if ($ this ->protocalVersion === 0xFF ) { //error
145
- $ fieldCount = $ this ->protocalVersion ;
146
- $ this ->protocalVersion = 0 ;
147
- printf ("Error: \n" );
148
-
149
- $ this ->rsState = self ::RS_STATE_HEADER ;
150
- $ this ->resultFields = [];
151
- if ($ this ->phase === self ::PHASE_AUTH_SENT || $ this ->phase === self ::PHASE_GOT_INIT ) {
152
- $ this ->phase = self ::PHASE_AUTH_ERR ;
153
- }
141
+ $ response = $ this ->buffer ->readInt1 ();
142
+ if ($ response === 0xFF ) {
143
+ // error packet before handshake means we did not exchange capabilities and error does not include SQL state
144
+ $ this ->phase = self ::PHASE_AUTH_ERR ;
145
+ $ this ->errno = $ this ->buffer ->readInt2 ();
146
+ $ this ->errmsg = $ this ->buffer ->read ($ this ->pctSize - $ len + $ this ->buffer ->length ());
147
+ $ this ->debug (sprintf ("Error Packet:%d %s \n" , $ this ->errno , $ this ->errmsg ));
154
148
155
- goto field;
149
+ // error during init phase also means we're not currently executing any command
150
+ // simply reject the first outstanding command in the queue (AuthenticateCommand)
151
+ $ this ->currCommand = $ this ->executor ->dequeue ();
152
+ $ this ->onError ();
153
+ return ;
156
154
}
157
155
158
- $ options = &$ this ->connectOptions ;
156
+ $ this ->phase = self ::PHASE_GOT_INIT ;
157
+ $ this ->protocalVersion = $ response ;
158
+ $ this ->debug (sprintf ("Protocal Version: %d " , $ this ->protocalVersion ));
159
159
160
+ $ options = &$ this ->connectOptions ;
160
161
$ options ['serverVersion ' ] = $ this ->buffer ->readStringNull ();
161
162
$ options ['threadId ' ] = $ this ->buffer ->readInt4 ();
162
163
$ this ->scramble = $ this ->buffer ->read (8 ); // 1st part
@@ -173,14 +174,15 @@ public function parse($data)
173
174
$ this ->buffer ->readStringNull (); // skip authentication plugin name
174
175
}
175
176
177
+ // init completed, continue with sending AuthenticateCommand
176
178
$ this ->nextRequest (true );
177
179
} else {
178
180
$ fieldCount = $ this ->buffer ->readInt1 ();
179
- field:
181
+
180
182
if ($ fieldCount === 0xFF ) {
181
183
// error packet
182
184
$ this ->errno = $ this ->buffer ->readInt2 ();
183
- $ this ->buffer ->skip (6 ); // state
185
+ $ this ->buffer ->skip (6 ); // skip SQL state
184
186
$ this ->errmsg = $ this ->buffer ->read ($ this ->pctSize - $ len + $ this ->buffer ->length ());
185
187
$ this ->debug (sprintf ("Error Packet:%d %s \n" , $ this ->errno , $ this ->errmsg ));
186
188
0 commit comments