Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
afi
zf
Commits
363f6e83
Commit
363f6e83
authored
Nov 07, 2014
by
Patrick Barroca
😁
Browse files
Merge branch 'hotline#17179-mysql-gone-away' into 'master'
Hotline#17179 mysql gone away See merge request
!1
parents
8ebe9ed4
b83a76ba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
44 deletions
+94
-44
library/Zend/Db/Adapter/Abstract.php
library/Zend/Db/Adapter/Abstract.php
+31
-5
library/Zend/Db/Adapter/Mysqli.php
library/Zend/Db/Adapter/Mysqli.php
+26
-8
library/Zend/Db/Statement/Mysqli.php
library/Zend/Db/Statement/Mysqli.php
+12
-4
library/Zend/Db/Statement/Mysqli/Unprepared.php
library/Zend/Db/Statement/Mysqli/Unprepared.php
+25
-27
No files found.
library/Zend/Db/Adapter/Abstract.php
View file @
363f6e83
...
...
@@ -441,11 +441,16 @@ abstract class Zend_Db_Adapter_Abstract
return
$stmt
;
}
return
new
Zend_Db_Statement_Mysqli_Unprepared
(
$this
->
getConnection
()
->
query
(
$sql
),
$this
->
_fetchMode
);
$result
=
$this
->
withReconnectDo
(
function
()
use
(
$sql
)
{
$result
=
$this
->
getConnection
()
->
query
(
$sql
);
if
(
false
===
$result
)
throw
new
Zend_Db_Exception
(
$this
->
getConnection
()
->
error
,
$this
->
getConnection
()
->
errno
);
return
$result
;
});
return
new
Zend_Db_Statement_Mysqli_Unprepared
(
$this
,
$result
,
$this
->
_fetchMode
);
}
/**
...
...
@@ -1053,6 +1058,27 @@ abstract class Zend_Db_Adapter_Abstract
return
$this
;
}
public
function
withReconnectDo
(
$closure
)
{
try
{
return
$closure
();
}
catch
(
Zend_Db_Exception
$e
){
if
(
$this
->
shouldRetry
(
$e
))
{
$this
->
closeConnection
();
return
$closure
();
}
throw
$e
;
}
}
protected
function
shouldRetry
(
$exception
)
{
return
'2006'
==
$exception
->
getCode
();
// Server has gone away
}
/**
* Abstract Methods
*/
...
...
library/Zend/Db/Adapter/Mysqli.php
View file @
363f6e83
...
...
@@ -129,9 +129,17 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
*
* @return array
*/
public
function
listTables
()
{
$result
=
array
();
public
function
listTables
()
{
return
$this
->
withReconnectDo
(
function
()
{
return
$this
->
_realListTables
();
});
}
protected
function
_realListTables
()
{
$result
=
[];
// Use mysqli extension API, because SHOW doesn't work
// well as a prepared statement on MySQL 4.1.
$sql
=
'SHOW TABLES'
;
...
...
@@ -145,7 +153,8 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once
'Zend/Db/Adapter/Mysqli/Exception.php'
;
throw
new
Zend_Db_Adapter_Mysqli_Exception
(
$this
->
getConnection
()
->
error
);
throw
new
Zend_Db_Exception
(
$this
->
getConnection
()
->
error
,
$this
->
getConnection
()
->
errno
);
}
return
$result
;
}
...
...
@@ -178,8 +187,15 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
* @param string $schemaName OPTIONAL
* @return array
*/
public
function
describeTable
(
$tableName
,
$schemaName
=
null
)
{
public
function
describeTable
(
$tableName
,
$schemaName
=
null
)
{
return
$this
->
withReconnectDo
(
function
()
use
(
$tableName
,
$schemaName
)
{
return
$this
->
_realDescribeTable
(
$tableName
,
$schemaName
);
});
}
protected
function
_realDescribeTable
(
$tableName
,
$schemaName
)
{
/**
* @todo use INFORMATION_SCHEMA someday when
* MySQL's implementation isn't too slow.
...
...
@@ -205,7 +221,8 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
* @see Zend_Db_Adapter_Mysqli_Exception
*/
require_once
'Zend/Db/Adapter/Mysqli/Exception.php'
;
throw
new
Zend_Db_Adapter_Mysqli_Exception
(
$this
->
getConnection
()
->
error
);
throw
new
Zend_Db_Exception
(
$this
->
getConnection
()
->
error
,
$this
->
getConnection
()
->
errno
);
}
$desc
=
array
();
...
...
@@ -269,7 +286,8 @@ class Zend_Db_Adapter_Mysqli extends Zend_Db_Adapter_Abstract
++
$i
;
}
return
$desc
;
}
}
/**
* Creates a connection to the database.
...
...
library/Zend/Db/Statement/Mysqli.php
View file @
363f6e83
...
...
@@ -26,7 +26,7 @@
*/
require_once
'Zend/Db/Statement.php'
;
/**
* Extends for Mysqli
*
...
...
@@ -70,10 +70,17 @@ class Zend_Db_Statement_Mysqli extends Zend_Db_Statement
* @return void
* @throws Zend_Db_Statement_Mysqli_Exception
*/
public
function
_prepare
(
$sql
)
public
function
_prepare
(
$sql
)
{
return
$this
->
_adapter
->
withReconnectDo
(
function
()
use
(
$sql
)
{
return
$this
->
_realPrepare
(
$sql
);
});
}
public
function
_realPrepare
(
$sql
)
{
$mysqli
=
$this
->
_adapter
->
getConnection
();
$this
->
_stmt
=
$mysqli
->
prepare
(
$sql
);
if
(
$this
->
_stmt
===
false
||
$mysqli
->
errno
)
{
...
...
@@ -81,7 +88,8 @@ class Zend_Db_Statement_Mysqli extends Zend_Db_Statement
* @see Zend_Db_Statement_Mysqli_Exception
*/
require_once
'Zend/Db/Statement/Mysqli/Exception.php'
;
throw
new
Zend_Db_Statement_Mysqli_Exception
(
"Mysqli prepare error: "
.
$mysqli
->
error
.
" "
.
$sql
);
throw
new
Zend_Db_Statement_Mysqli_Exception
(
"Mysqli prepare error: "
.
$mysqli
->
error
.
" "
.
$sql
,
$mysqli
->
errno
);
}
}
...
...
library/Zend/Db/Statement/Mysqli/Unprepared.php
View file @
363f6e83
...
...
@@ -4,39 +4,39 @@
*/
//require_once 'Zend/Db/Statement.php';
class
Zend_Db_Statement_Mysqli_Unprepared
extends
Zend_Db_Statement
{
class
Zend_Db_Statement_Mysqli_Unprepared
extends
Zend_Db_Statement
{
protected
$_fetchMode
,
$_result
;
public
function
__construct
(
$result
,
$fetchMode
)
{
$this
->
_result
=
$result
;
public
function
__construct
(
$adapter
,
$result
,
$fetchMode
)
{
if
(
false
===
$result
)
throw
new
Zend_Db_Exception
(
$adapter
->
getConnection
()
->
error
,
$adapter
->
getConnection
()
->
errno
);
$this
->
_adapter
=
$adapter
;
$this
->
_result
=
$result
;
$this
->
_fetchMode
=
$fetchMode
;
}
public
function
fetchAll
(
$fetchMode
=
null
,
$col
=
null
)
{
$data
=
array
()
;
while
(
$row
=
$this
->
fetch
(
$fetchMode
))
{
public
function
fetchAll
(
$fetchMode
=
null
,
$col
=
null
)
{
$data
=
[]
;
while
(
$row
=
$this
->
fetch
(
$fetchMode
))
array_push
(
$data
,
$row
);
}
return
$data
;
}
public
function
fetchColumn
(
$col
=
0
)
{
public
function
fetchColumn
(
$col
=
0
)
{
$row
=
$this
->
fetch
(
Zend_Db
::
FETCH_NUM
);
if
(
isset
(
$row
[
$col
]))
{
if
(
isset
(
$row
[
$col
]))
return
$row
[
$col
];
}
return
false
;
// FIXME
}
public
function
fetch
(
$fetchMode
=
null
,
$cursor
=
null
,
$offset
=
null
)
{
if
(
$fetchMode
===
null
)
{
public
function
fetch
(
$fetchMode
=
null
,
$cursor
=
null
,
$offset
=
null
)
{
if
(
$fetchMode
===
null
)
$fetchMode
=
$this
->
_fetchMode
;
}
switch
(
$fetchMode
)
{
default
:
...
...
@@ -56,8 +56,8 @@ class Zend_Db_Statement_Mysqli_Unprepared extends Zend_Db_Statement
return
$this
->
_result
->
fetch_array
(
$fetchMode
);
}
public
function
__call
(
$method
,
$args
)
{
public
function
__call
(
$method
,
$args
)
{
die
(
"
$method
"
);
}
...
...
@@ -66,6 +66,7 @@ class Zend_Db_Statement_Mysqli_Unprepared extends Zend_Db_Statement
return
true
;
}
public
function
columnCount
()
{
return
0
;
}
...
...
@@ -75,7 +76,6 @@ class Zend_Db_Statement_Mysqli_Unprepared extends Zend_Db_Statement
return
''
;
}
public
function
errorInfo
()
{
return
''
;
}
...
...
@@ -89,8 +89,7 @@ class Zend_Db_Statement_Mysqli_Unprepared extends Zend_Db_Statement
* @return bool
* @throws Zend_Db_Statement_Mysqli_Exception
*/
public
function
nextRowset
()
{
public
function
nextRowset
()
{
/**
* @see Zend_Db_Statement_Mysqli_Exception
*/
...
...
@@ -106,11 +105,10 @@ class Zend_Db_Statement_Mysqli_Unprepared extends Zend_Db_Statement
*
* @return int The number of rows affected.
*/
public
function
rowCount
()
{
if
(
!
$this
->
_adapter
)
{
public
function
rowCount
()
{
if
(
!
$this
->
_adapter
)
return
false
;
}
$mysqli
=
$this
->
_adapter
->
getConnection
();
return
$mysqli
->
affected_rows
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment