Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezdbinterface.php
Go to the documentation of this file.
1 <?php
19 class eZDBInterface
20 {
21 const BINDING_NO = 0;
22 const BINDING_NAME = 1;
23 const BINDING_ORDERED = 2;
24
25 const RELATION_TABLE = 0;
26 const RELATION_SEQUENCE = 1;
27 const RELATION_TRIGGER = 2;
28 const RELATION_VIEW = 3;
29 const RELATION_INDEX = 4;
30
31 const RELATION_TABLE_BIT = 1;
32 const RELATION_SEQUENCE_BIT = 2;
33 const RELATION_TRIGGER_BIT = 4;
34 const RELATION_VIEW_BIT = 8;
35 const RELATION_INDEX_BIT = 16;
36
37 const RELATION_NONE = 0;
38 const RELATION_MASK = 31;
39
40 const ERROR_MISSING_EXTENSION = 1;
41
42 const SERVER_MASTER = 1;
43 const SERVER_SLAVE = 2;
44
50 const MAX_INT = 2147483647;
51
57 const MIN_INT = -2147483648;
58
64 public function __construct( $parameters )
65 {
66 $server = $parameters['server'];
67 $port = $parameters['port'];
68 $user = $parameters['user'];
69 $password = $parameters['password'];
70 $db = $parameters['database'];
71 $useSlaveServer = $parameters['use_slave_server'];
72 $slaveServer = $parameters['slave_server'];
73 $slavePort = $parameters['slave_port'];
74 $slaveUser = $parameters['slave_user'];
75 $slavePassword = $parameters['slave_password'];
76 $slaveDB = $parameters['slave_database'];
77 $socketPath = $parameters['socket'];
78 $charset = $parameters['charset'];
79 $isInternalCharset = $parameters['is_internal_charset'];
80 $builtinEncoding = $parameters['builtin_encoding'];
81 $connectRetries = $parameters['connect_retries'];
82
83 if ( $parameters['use_persistent_connection'] == 'enabled' )
84 {
85 $this->UsePersistentConnection = true;
86 }
87
88 $this->DB = $db;
89 $this->Server = $server;
90 $this->Port = $port;
91 $this->SocketPath = $socketPath;
92 $this->User = $user;
93 $this->Password = $password;
94 $this->UseSlaveServer = $useSlaveServer;
95 $this->SlaveDB = $slaveDB;
96 $this->SlaveServer = $slaveServer;
97 $this->SlavePort = $slavePort;
98 $this->SlaveUser = $slaveUser;
99 $this->SlavePassword = $slavePassword;
100 $this->Charset = $charset;
101 $this->IsInternalCharset = $isInternalCharset;
102 $this->UseBuiltinEncoding = $builtinEncoding;
103 $this->ConnectRetries = $connectRetries;
104 $this->DBConnection = false;
105 $this->DBWriteConnection = false;
106 $this->TransactionCounter = 0;
107 $this->TransactionIsValid = false;
108 $this->TransactionStackTree = false;
109
110 $this->OutputTextCodec = null;
111 $this->InputTextCodec = null;
112
113 $tmpOutputTextCodec = eZTextCodec::instance( $charset, false, false );
114 $tmpInputTextCodec = eZTextCodec::instance( false, $charset, false );
115 unset( $this->OutputTextCodec );
116 unset( $this->InputTextCodec );
117 $this->OutputTextCodec = null;
118 $this->InputTextCodec = null;
119
120 if ( $tmpOutputTextCodec && $tmpInputTextCodec )
121 {
122 if ( $tmpOutputTextCodec->conversionRequired() && $tmpInputTextCodec->conversionRequired() )
123 {
124 $this->OutputTextCodec =& $tmpOutputTextCodec;
125 $this->InputTextCodec =& $tmpInputTextCodec;
126 }
127 }
128
129 $this->OutputSQL = false;
130 $this->SlowSQLTimeout = 0;
131 $ini = eZINI::instance();
132 if ( ( $ini->variable( "DatabaseSettings", "SQLOutput" ) == "enabled" ) and
133 ( $ini->variable( "DebugSettings", "DebugOutput" ) == "enabled" ) )
134 {
135 $this->OutputSQL = true;
136
137 $this->SlowSQLTimeout = (int) $ini->variable( "DatabaseSettings", "SlowQueriesOutput" );
138 }
139 if ( $ini->variable( "DatabaseSettings", "DebugTransactions" ) == "enabled" )
140 {
141 // Setting it to an array turns on the debugging
142 $this->TransactionStackTree = array();
143 }
144
145 $this->QueryAnalysisOutput = false;
146 if ( $ini->variable( "DatabaseSettings", "QueryAnalysisOutput" ) == "enabled" )
147 {
148 $this->QueryAnalysisOutput = true;
149 }
150
151 $this->IsConnected = false;
152 $this->NumQueries = 0;
153 $this->StartTime = false;
154 $this->EndTime = false;
155 $this->TimeTaken = false;
156
157 $this->AttributeVariableMap =
158 array(
159 'database_name' => 'DB',
160 'database_server' => 'Server',
161 'database_port' => 'Port',
162 'database_socket_path' => 'SocketPath',
163 'database_user' => 'User',
164 'use_slave_server' => 'UseSlaveServer',
165 'slave_database_name' => 'SlaveDB',
166 'slave_database_server' => 'SlaveServer',
167 'slave_database_port' => 'SlavePort',
168 'slave_database_user' => 'SlaveUser',
169 'charset' => 'Charset',
170 'is_internal_charset' => 'IsInternalCharset',
171 'use_builting_encoding' => 'UseBuiltinEncoding',
172 'retry_count' => 'ConnectRetries' );
173 }
174
180 function attributes()
181 {
182 return array_keys( $this->AttributeVariableMap );
183 }
184
191 function hasAttribute( $name )
192 {
193 if ( isset( $this->AttributeVariableMap[$name] ) )
194 {
195 return true;
196 }
197 return false;
198 }
199
206 function attribute( $name )
207 {
208 if ( isset( $this->AttributeVariableMap[$name] ) )
209 {
210 $memberVariable = $this->AttributeVariableMap[$name];
211 return $this->$memberVariable;
212 }
213 else
214 {
215 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
216 return null;
217 }
218 }
219
229 function checkCharset( $charset, &$currentCharset )
230 {
231 return true;
232 }
233
242 function prepareSqlQuery( &$fd, &$buffer )
243 {
244
245 $sqlQueryArray = array();
246 while( count( $sqlQueryArray ) == 0 && !feof( $fd ) )
247 {
248 $buffer .= fread( $fd, 4096 );
249 if ( $buffer )
250 {
251 // Fix SQL file by deleting all comments and newlines
252 // eZDebug::writeDebug( $buffer, "read data" );
253 $sqlQuery = preg_replace( array( "/^#.*\n" . "/m",
254 "#^/\*.*\*/\n" . "#m",
255 "/^--.*\n" . "/m",
256 "/\n|\r\n|\r/m" ),
257 array( "",
258 "",
259 "",
260 "\n" ),
261 $buffer );
262 // eZDebug::writeDebug( $sqlQuery, "read data" );
263
264 // Split the query into an array
265 $sqlQueryArray = preg_split( "/;\n/m", $sqlQuery );
266
267 if ( preg_match( '/;\n/m', $sqlQueryArray[ count( $sqlQueryArray ) -1 ] ) )
268 {
269 $buffer = '';
270 }
271 else
272 {
273 $buffer = $sqlQueryArray[ count( $sqlQueryArray ) -1 ];
274 array_splice( $sqlQueryArray, count( $sqlQueryArray ) -1 , 1 );
275 }
276 }
277 else
278 {
279 return $sqlQueryArray;
280
281 }
282 }
283 return $sqlQueryArray;
284 }
285
294 function insertFile( $path, $sqlFile, $usePathType = true )
295 {
296 $type = $this->databaseName();
297
298 if ( $usePathType )
299 $sqlFileName = eZDir::path( array( $path, $type, $sqlFile ) );
300 else
301 $sqlFileName = eZDir::path( array( $path, $sqlFile ) );
302 if ( !file_exists( $sqlFileName ) )
303 {
304 eZDebug::writeError( "File not found: $sqlFileName", __METHOD__ );
305 return false;
306 }
307 $sqlFileHandler = fopen( $sqlFileName, 'rb' );
308 $buffer = '';
309 $done = false;
310 while ( count( ( $sqlArray = $this->prepareSqlQuery( $sqlFileHandler, $buffer ) ) ) > 0 )
311 {
312 // Turn unneccessary SQL debug output off
313 $oldOutputSQL = $this->OutputSQL;
314 $this->OutputSQL = false;
315 if ( $sqlArray && is_array( $sqlArray ) )
316 {
317 $done = true;
318 foreach( $sqlArray as $singleQuery )
319 {
320 $singleQuery = preg_replace( "/\n|\r\n|\r/", " ", $singleQuery );
321 if ( preg_match( "#^ */(.+)$#", $singleQuery, $matches ) )
322 {
323 $singleQuery = $matches[1];
324 }
325 if ( trim( $singleQuery ) != "" )
326 {
327 // eZDebug::writeDebug( $singleQuery );
328 $this->query( trim( $singleQuery ) );
329 if ( $this->errorNumber() )
330 {
331 return false;
332 }
333 }
334 }
335
336 }
337 $this->OutputSQL = $oldOutputSQL;
338 }
339 return $done;
340
341 }
342
353 function reportQuery( $class, $sql, $numRows, $timeTaken, $asDebug = false )
354 {
355 $rowText = '';
356 if ( $numRows !== false ) $rowText = "$numRows rows, ";
357
358 $backgroundClass = ($this->TransactionCounter > 0 ? "debugtransaction transactionlevel-$this->TransactionCounter" : '');
359 if ( $asDebug )
360 eZDebug::writeDebug( "$sql", "$class::query($rowText" . number_format( $timeTaken, 3 ) . ' ms) query number per page:' . $this->NumQueries++, $backgroundClass );
361 else
362 eZDebug::writeNotice( "$sql", "$class::query($rowText" . number_format( $timeTaken, 3 ) . ' ms) query number per page:' . $this->NumQueries++, $backgroundClass );
363 }
364
370 function setIsSQLOutputEnabled( $enabled )
371 {
372 $this->OutputSQL = $enabled;
373 }
374
380 function startTimer()
381 {
382 $this->StartTime = microtime( true );
383 }
384
390 function endTimer()
391 {
392 $this->EndTime = microtime( true );
393 // Calculate time taken in ms
394 $this->TimeTaken = $this->EndTime - $this->StartTime;
395 $this->TimeTaken *= 1000.0;
396 }
397
404 function startTime()
405 {
406 return $this->StartTime;
407 }
408
415 function endTime()
416 {
417 return $this->EndTime;
418 }
419
426 function timeTaken()
427 {
428 return $this->TimeTaken;
429 }
430
438 function databaseName()
439 {
440 return '';
441 }
442
448 function socketPath()
449 {
450 return $this->SocketPath;
451 }
452
458 function connectRetryCount()
459 {
460 return $this->ConnectRetries;
461 }
462
468 function connectRetryWaitTime()
469 {
470 return 3;
471 }
472
478 function supportedRelationTypeMask()
479 {
480 return eZDBInterface::RELATION_NONE;
481 }
482
488 function useShortNames()
489 {
490 return false;
491 }
492
497 function supportedRelationTypes()
498 {
499 return array();
500 }
501
510 function subString( $string, $from, $len = null )
511 {
512 return '';
513 }
514
521 function concatString( $strings = array() )
522 {
523 return '';
524 }
525
532 function md5( $str )
533 {
534 return '';
535 }
536
544 function bitAnd( $arg1, $arg2 )
545 {
546 return '(' . $arg1 . ' & ' . $arg2 . ' ) ';
547 }
548
556 function bitOr( $arg1, $arg2 )
557 {
558 return '( ' . $arg1 . ' | ' . $arg2 . ' ) ';
559 }
560
570 function hasRequiredServerVersion( $minVersion, $name = false )
571 {
572 if ( $name !== false and
573 $name != $this->databaseName() )
574 return false;
575
576 $version = $this->databaseServerVersion();
577 $version = $version['string'];
578 return version_compare( $version, $minVersion ) >= 0;
579 }
580
586 function databaseServerVersion()
587 {
588 }
589
595 function databaseClientVersion()
596 {
597 }
598
605 function isCharsetSupported( $charset )
606 {
607 return false;
608 }
609
616 function charset()
617 {
618 return $this->Charset;
619 }
620
628 function usesBuiltinEncoding()
629 {
630 return $this->UseBuiltinEncoding;
631 }
632
638 function bindingType()
639 {
640 }
641
649 function bindVariable( $value, $fieldDef = false )
650 {
651 }
652
661 function query( $sql, $server = false )
662 {
663 }
664
681 function arrayQuery( $sql, $params = array(), $server = false )
682 {
683 }
684
690 function lock( $table )
691 {
692 }
693
699 function unlock()
700 {
701 }
702
710 function begin()
711 {
712 $ini = eZINI::instance();
713 if ($ini->variable( "DatabaseSettings", "Transactions" ) == "enabled")
714 {
715 if ( $this->TransactionCounter > 0 )
716 {
717 if ( is_array( $this->TransactionStackTree ) )
718 {
719 // Make a new sub-level for debugging
720 $bt = debug_backtrace();
721 $subLevels =& $this->TransactionStackTree['sub_levels'];
722 for ( $i = 1; $i < $this->TransactionCounter; ++$i )
723 {
724 $subLevels =& $subLevels[count( $subLevels ) - 1]['sub_levels'];
725 }
726 // Next entry will be at the end
727 $subLevels[count( $subLevels )] = array( 'level' => $this->TransactionCounter,
728 'trace' => $bt,
729 'sub_levels' => array() );
730 }
731 ++$this->TransactionCounter;
732 return false;
733 }
734 else
735 {
736 if ( is_array( $this->TransactionStackTree ) )
737 {
738 // Start new stack tree for debugging
739 $bt = debug_backtrace();
740 $this->TransactionStackTree = array( 'level' => $this->TransactionCounter,
741 'trace' => $bt,
742 'sub_levels' => array() );
743 }
744 }
745 $this->TransactionIsValid = true;
746
747 if ( $this->isConnected() )
748 {
749 $oldRecordError = $this->RecordError;
750 // Turn off error handling while we begin
751 $this->RecordError = false;
752 $this->beginQuery();
753 $this->RecordError = $oldRecordError;
754
755 // We update the transaction counter after the query, otherwise we
756 // mess up the debug background highlighting.
757 ++$this->TransactionCounter;
758 }
759 }
760 return true;
761 }
762
770 function beginQuery()
771 {
772 return false;
773 }
774
785 function commit()
786 {
787 $ini = eZINI::instance();
788 if ($ini->variable( "DatabaseSettings", "Transactions" ) == "enabled")
789 {
790 if ( $this->TransactionCounter <= 0 )
791 {
792 eZDebug::writeError( 'No transaction in progress, cannot commit', __METHOD__ );
793 return false;
794 }
795
796 --$this->TransactionCounter;
797 if ( $this->TransactionCounter == 0 )
798 {
799 if ( is_array( $this->TransactionStackTree ) )
800 {
801 // Reset the stack debug tree since the top commit was done
802 $this->TransactionStackTree = array();
803 }
804 if ( $this->isConnected() )
805 {
806 // Check if we have encountered any problems, if so we have to rollback
807 if ( !$this->TransactionIsValid )
808 {
809 $oldRecordError = $this->RecordError;
810 // Turn off error handling while we rollback
811 $this->RecordError = false;
812 $this->rollbackQuery();
813 $this->RecordError = $oldRecordError;
814
815 return false;
816 }
817 else
818 {
819 $oldRecordError = $this->RecordError;
820 // Turn off error handling while we commit
821 $this->RecordError = false;
822 $this->commitQuery();
823 $this->RecordError = $oldRecordError;
824 }
825 }
826 }
827 else
828 {
829 if ( is_array( $this->TransactionStackTree ) )
830 {
831 // Close the last open nested transaction
832 $bt = debug_backtrace();
833 // Store commit trace
834 $subLevels =& $this->TransactionStackTree['sub_levels'];
835 for ( $i = 1; $i < $this->TransactionCounter; ++$i )
836 {
837 $subLevels =& $subLevels[count( $subLevels ) - 1]['sub_levels'];
838 }
839 // Find last entry and add the commit trace
840 $subLevels[count( $subLevels ) - 1]['commit_trace'] = $bt;
841 }
842 }
843 }
844 return true;
845 }
846
854 function commitQuery()
855 {
856 return false;
857 }
858
864 function rollback()
865 {
866 if ( is_array( $this->TransactionStackTree ) )
867 {
868 // All transactions were rollbacked, reset the tree.
869 $this->TransactionStackTree = array();
870 }
871 $ini = eZINI::instance();
872 if ($ini->variable( "DatabaseSettings", "Transactions" ) == "enabled")
873 {
874 if ( $this->TransactionCounter <= 0 )
875 {
876 eZDebug::writeError( 'No transaction in progress, cannot rollback', __METHOD__ );
877 return false;
878 }
879 // Reset the transaction counter
880 $this->TransactionCounter = 0;
881 if ( $this->isConnected() )
882 {
883 $oldRecordError = $this->RecordError;
884 // Turn off error handling while we rollback
885 $this->RecordError = false;
886 $this->rollbackQuery();
887 $this->RecordError = $oldRecordError;
888 }
889 }
890 return true;
891 }
892
902 function generateFailedTransactionStack()
903 {
904 if ( !$this->TransactionStackTree )
905 {
906 return false;
907 }
908 return $this->generateFailedTransactionStackEntry( $this->TransactionStackTree, 0 );
909 }
910
919 function generateFailedTransactionStackEntry( $stack, $indentCount )
920 {
921 $stackText = '';
922 $indent = '';
923 if ( $indentCount > 0 )
924 {
925 $indent = str_repeat( " ", $indentCount*4 );
926 }
927 $stackText .= $indent . "Level " . $stack['level'] . "\n" . $indent . "{" . $indent . "\n";
928 $stackText .= $indent . " Began at:\n";
929 for ( $i = 0; $i < 2 && $i < count( $stack['trace'] ); ++$i )
930 {
931 $indent2 = str_repeat( " ", $i + 1 );
932 if ( $i > 0 )
933 {
934 $indent2 .= "->";
935 }
936 $stackText .= $indent . $indent2 . $this->generateTraceEntry( $stack['trace'][$i] );
937 $stackText .= "\n";
938 }
939 foreach ( $stack['sub_levels'] as $subStack )
940 {
941 $stackText .= $this->generateFailedTransactionStackEntry( $subStack, $indentCount + 1 );
942 }
943 if ( isset( $stack['commit_trace'] ) )
944 {
945 $stackText .= $indent . " And commited at:\n";
946 for ( $i = 0; $i < 2 && $i < count( $stack['commit_trace'] ); ++$i )
947 {
948 $indent2 = str_repeat( " ", $i + 1 );
949 if ( $i > 0 )
950 {
951 $indent2 .= "->";
952 }
953 $stackText .= $indent . $indent2 . $this->generateTraceEntry( $stack['commit_trace'][$i] );
954 $stackText .= "\n";
955 }
956 }
957 $stackText .= $indent . "}" . "\n";
958 return $stackText;
959 }
960
968 function generateTraceEntry( $entry )
969 {
970 if ( isset( $entry['file'] ) )
971 {
972 $stackText = $entry['file'];
973 }
974 else
975 {
976 $stackText = "???";
977 }
978 $stackText .= ":";
979 if ( isset( $entry['line'] ) )
980 {
981 $stackText .= $entry['line'];
982 }
983 else
984 {
985 $stackText .= "???";
986 }
987 $stackText .= " ";
988 if ( isset( $entry['class'] ) )
989 {
990 $stackText .= $entry['class'];
991 }
992 else
993 {
994 $stackText .= "???";
995 }
996 $stackText .= "::";
997 if ( isset( $entry['function'] ) )
998 {
999 $stackText .= $entry['function'];
1000 }
1001 else
1002 {
1003 $stackText .= "???";
1004 }
1005 return $stackText;
1006 }
1007
1015 function rollbackQuery()
1016 {
1017 return false;
1018 }
1019
1026 function invalidateTransaction()
1027 {
1028 if ( $this->TransactionCounter <= 0 )
1029 return false;
1030 $this->TransactionIsValid = false;
1031 return true;
1032 }
1033
1042 function reportError()
1043 {
1044 // If we have a running transaction we must mark as invalid
1045 // in which case a call to commit() will perform a rollback
1046 if ( $this->TransactionCounter > 0 )
1047 {
1048 $this->invalidateTransaction();
1049
1050 // This is the unique ID for this incidence which will also be placed in the error logs.
1051 $transID = 'TRANSID-' . md5( time() . mt_rand() );
1052
1053 eZDebug::writeError( 'Transaction in progress failed due to DB error, transaction was rollbacked. Transaction ID is ' . $transID . '.', 'eZDBInterface::commit ' . $transID );
1054
1055 $this->rollback();
1056
1057 if ( $this->errorHandling == eZDB::ERROR_HANDLING_EXCEPTIONS )
1058 {
1059 throw new eZDBException( $this->ErrorMessage, $this->ErrorNumber );
1060 }
1061 else
1062 {
1063 // Stop execution immediately while allowing other systems (session etc.) to cleanup
1064 eZExecution::cleanup();
1065 eZExecution::setCleanExit();
1066
1067 // Give some feedback, and also possibly show the debug output
1068 eZDebug::setHandleType( eZDebug::HANDLE_NONE );
1069
1070 $ini = eZINI::instance();
1071 $adminEmail = $ini->variable( 'MailSettings', 'AdminEmail' );
1072 if ( !eZSys::isShellExecution() )
1073 {
1074 if ( !headers_sent() )
1075 {
1076 header("HTTP/1.1 500 Internal Server Error");
1077 }
1078 $site = htmlentities(eZSys::serverVariable( 'HTTP_HOST' ), ENT_QUOTES);
1079 $uri = htmlentities(eZSys::serverVariable( 'REQUEST_URI' ), ENT_QUOTES);
1080
1081 print( "<div class=\"fatal-error\" style=\"" );
1082 print( 'margin: 0.5em 0 1em 0; ' .
1083 'padding: 0.25em 1em 0.75em 1em;' .
1084 'border: 4px solid #000000;' .
1085 'background-color: #f8f8f4;' .
1086 'border-color: #f95038;" >' );
1087 print( "<b>Fatal error</b>: A database transaction in eZ Publish failed.<br/>" );
1088 print( "<p>" );
1089 print( "The current execution was stopped to prevent further problems.<br/>\n" .
1090 "You should contact the <a href=\"mailto:$adminEmail?subject=Transaction failed on $site and URI $uri with ID $transID\">System Administrator</a> of this site with the information on this page.<br/>\n" .
1091 "The current transaction ID is <b>$transID</b> and has been logged.<br/>\n" .
1092 "Please include the transaction ID and the current URL when contacting the system administrator.<br/>\n" );
1093 print( "</p>" );
1094 print( "</div>" );
1095
1096 $templateResult = null;
1097 if ( function_exists( 'eZDisplayResult' ) )
1098 {
1099 eZDisplayResult( $templateResult );
1100 }
1101 }
1102 else
1103 {
1104 fputs( STDERR,"Fatal error: A database transaction in eZ Publish failed.\n" );
1105 fputs( STDERR, "\n" );
1106 fputs( STDERR, "The current execution was stopped to prevent further problems.\n" .
1107 "You should contact the System Administrator ($adminEmail) of this site.\n" .
1108 "The current transaction ID is $transID and has been logged.\n" .
1109 "Please include the transaction ID and the name of the current script when contacting the system administrator.\n" );
1110 fputs( STDERR, "\n" );
1111
1112 fputs( STDERR, eZDebug::printReport( false, false, true ) );
1113 }
1114
1115 // PHP execution stops here
1116 exit( 1 );
1117 }
1118 }
1119 }
1120
1127 function isTransactionValid()
1128 {
1129 return $this->TransactionIsValid;
1130 }
1131
1140 function transactionCounter()
1141 {
1142 return $this->TransactionCounter;
1143 }
1144
1151 function relationCounts( $relationMask )
1152 {
1153 }
1154
1161 function relationCount( $relationType = eZDBInterface::RELATION_TABLE )
1162 {
1163 }
1164
1171 function eZTableList( $server = self::SERVER_MASTER )
1172 {
1173 }
1174
1181 function relationList( $relationType = eZDBInterface::RELATION_TABLE )
1182 {
1183 }
1184
1192 function removeRelation( $relationName, $relationType )
1193 {
1194 return false;
1195 }
1196
1206 function relationName( $relationType )
1207 {
1208 $names = array( eZDBInterface::RELATION_TABLE => 'TABLE',
1209 eZDBInterface::RELATION_SEQUENCE => 'SEQUENCE',
1210 eZDBInterface::RELATION_TRIGGER => 'TRIGGER',
1211 eZDBInterface::RELATION_VIEW => 'VIEW',
1212 eZDBInterface::RELATION_INDEX => 'INDEX' );
1213 if ( !isset( $names[$relationType] ) )
1214 return false;
1215 return $names[$relationType];
1216 }
1217
1233 function relationMatchRegexp( $relationType )
1234 {
1235 return false;
1236 }
1237
1252 function implodeWithTypeCast( $glue, &$pieces, $type )
1253 {
1254 $str = '';
1255 if ( !is_array( $pieces ) )
1256 return $str;
1257
1258 foreach( $pieces as $piece )
1259 {
1260 settype( $piece, $type );
1261 $str .= $piece.$glue;
1262 }
1263 $str = rtrim( $str, $glue );
1264 return $str;
1265 }
1266
1274 function lastSerialID( $table = false, $column = false )
1275 {
1276 }
1277
1284 function escapeString( $str )
1285 {
1286 return $str;
1287 }
1288
1294 function close()
1295 {
1296 }
1297
1304 function isConnected()
1305 {
1306 return $this->IsConnected;
1307 }
1308
1315 function createDatabase( $dbName )
1316 {
1317 }
1318
1325 function removeDatabase( $dbName )
1326 {
1327 }
1328
1335 function createTempTable( $createTableQuery = '', $server = self::SERVER_SLAVE )
1336 {
1337 $this->query( $createTableQuery, $server );
1338 }
1339
1347 function dropTempTable( $dropTableQuery = '', $server = self::SERVER_SLAVE )
1348 {
1349 $this->query( $dropTableQuery, $server );
1350 }
1351
1358 function dropTempTableList( $tableList, $server = self::SERVER_SLAVE )
1359 {
1360 foreach( $tableList as $tableName )
1361 $this->dropTempTable( "DROP TABLE $tableName", $server );
1362 }
1363
1369 function setError()
1370 {
1371 }
1372
1378 function errorMessage()
1379 {
1380 return $this->ErrorMessage;
1381 }
1382
1388 function errorNumber()
1389 {
1390 return $this->ErrorNumber;
1391 }
1392
1399 function availableDatabases()
1400 {
1401 return false;
1402 }
1403
1420 function generateUniqueTempTableName( $pattern, $randomizeIndex = false, $server = self::SERVER_SLAVE )
1421 {
1422 $tableList = array_keys( $this->eZTableList( $server ) );
1423 if ( $randomizeIndex === false )
1424 {
1425 $randomizeIndex = mt_rand( 10, 1000 );
1426 }
1427 do
1428 {
1429 $uniqueTempTableName = str_replace( '%', $randomizeIndex, $pattern );
1430 $randomizeIndex++;
1431 } while ( in_array( $uniqueTempTableName, $tableList ) );
1432
1433 return $uniqueTempTableName;
1434 }
1435
1441 function version()
1442 {
1443 return false;
1444 }
1445
1477 function generateSQLINStatement( $elements, $columnName = '', $not = false, $unique = true, $type = false )
1478 {
1479 $result = '';
1480 $statement = $columnName . ' IN';
1481 if ( $not === true )
1482 {
1483 $statement = $columnName . ' NOT IN';
1484 }
1485
1486 if ( !is_array( $elements ) )
1487 {
1488 $elements = array( $elements );
1489 }
1490
1491 $impString = $type ? $this->implodeWithTypeCast( ', ', $elements, $type ) : implode( ', ', $elements );
1492 $result = $statement . ' ( ' . $impString . ' )';
1493
1494 return $result;
1495 }
1496
1502 function supportsDefaultValuesInsertion()
1503 {
1504 return true;
1505 }
1506
1515 public function setErrorHandling( $errorHandling )
1516 {
1517 if ( $errorHandling != eZDB::ERROR_HANDLING_EXCEPTIONS &&
1518 $errorHandling != eZDB::ERROR_HANDLING_STANDARD )
1519 throw new RuntimeException( "Unknown eZDB error handling mode $errorHandling" );
1520
1521 $this->errorHandling = $errorHandling;
1522 }
1523
1537 public function truncateString( $string, $maxLength, $fieldName, $truncationSuffix = '' )
1538 {
1539 if ( mb_strlen( $string, "utf-8" ) <= $maxLength )
1540 {
1541 return $string;
1542 }
1543
1544 eZDebug::writeDebug( $string, "truncation of $fieldName to max_length=". $maxLength );
1545
1546 return mb_substr( $string , 0, $maxLength - mb_strlen( $truncationSuffix, "utf-8" ), "utf-8" );
1547 }
1548
1559 public function countStringSize( $string )
1560 {
1561 if ( !is_string( $string ) )
1562 return 0;
1563 else
1564 return mb_strlen( $string, "utf-8" );
1565 }
1566
1573 public $Server;
1574
1581 public $Port;
1582
1589 public $SocketPath;
1590
1597 public $DB;
1598
1605 public $DBConnection;
1606
1613 public $DBWriteConnection;
1614
1621 public $User;
1622
1629 public $Password;
1630
1637 public $Charset;
1638
1645 public $ConnectRetries;
1646
1653 public $OutputTextCodec;
1654
1661 public $InputTextCodec;
1662
1669 public $UseBuiltinEncoding;
1670
1677 public $OutputSQL;
1678
1685 public $IsConnected = false;
1686
1693 public $NumQueries = 0;
1694
1701 public $StartTime;
1702
1709 public $EndTime;
1710
1717 public $TimeTaken;
1718
1725 public $ErrorMessage;
1726
1733 public $ErrorNumber = 0;
1734
1741 public $RecordError = true;
1742
1749 public $UsePersistentConnection = false;
1750
1757 public $UseSlaveServer;
1758
1765 public $SlaveDB;
1766
1773 public $SlaveServer;
1774
1781 public $SlavePort;
1782
1789 public $SlaveUser;
1790
1797 public $SlavePassword;
1798
1805 public $TransactionCounter;
1806
1813 public $TransactionIsValid;
1814
1821 public $TransactionStackTree;
1822
1828 protected $errorHandling = eZDB::ERROR_HANDLING_STANDARD;
1829
1830 public $IsInternalCharset;
1831 public $SlowSQLTimeout;
1832 public $QueryAnalysisOutput;
1833 public $AttributeVariableMap;
1834 }
1835
1836 ?>
eZDBInterface
Definition: ezdbinterface.php:20
eZDBInterface\BINDING_ORDERED
const BINDING_ORDERED
Definition: ezdbinterface.php:23
eZDBInterface\$RecordError
$RecordError
Definition: ezdbinterface.php:1741
eZDBInterface\startTimer
startTimer()
Definition: ezdbinterface.php:380
eZDBInterface\$SlowSQLTimeout
$SlowSQLTimeout
Definition: ezdbinterface.php:1831
eZDBInterface\charset
charset()
Definition: ezdbinterface.php:616
eZDBInterface\$ConnectRetries
$ConnectRetries
Definition: ezdbinterface.php:1645
eZDBInterface\setIsSQLOutputEnabled
setIsSQLOutputEnabled( $enabled)
Definition: ezdbinterface.php:370
eZDBInterface\RELATION_INDEX
const RELATION_INDEX
Definition: ezdbinterface.php:29
eZDBInterface\relationCounts
relationCounts( $relationMask)
Definition: ezdbinterface.php:1151
eZDBInterface\commitQuery
commitQuery()
Definition: ezdbinterface.php:854
eZDBInterface\$StartTime
$StartTime
Definition: ezdbinterface.php:1701
eZDBInterface\databaseName
databaseName()
Definition: ezdbinterface.php:438
eZDBInterface\$UsePersistentConnection
$UsePersistentConnection
Definition: ezdbinterface.php:1749
eZDBInterface\subString
subString( $string, $from, $len=null)
Definition: ezdbinterface.php:510
eZDBInterface\generateUniqueTempTableName
generateUniqueTempTableName( $pattern, $randomizeIndex=false, $server=self::SERVER_SLAVE)
Definition: ezdbinterface.php:1420
eZDBInterface\rollbackQuery
rollbackQuery()
Definition: ezdbinterface.php:1015
eZDBInterface\generateFailedTransactionStack
generateFailedTransactionStack()
Definition: ezdbinterface.php:902
eZDBInterface\$TransactionStackTree
$TransactionStackTree
Definition: ezdbinterface.php:1821
eZDBInterface\md5
md5( $str)
Definition: ezdbinterface.php:532
eZDBInterface\generateFailedTransactionStackEntry
generateFailedTransactionStackEntry( $stack, $indentCount)
Definition: ezdbinterface.php:919
eZDBInterface\reportQuery
reportQuery( $class, $sql, $numRows, $timeTaken, $asDebug=false)
Definition: ezdbinterface.php:353
eZDBInterface\$TransactionCounter
$TransactionCounter
Definition: ezdbinterface.php:1805
eZDBInterface\attribute
attribute( $name)
Definition: ezdbinterface.php:206
eZDBInterface\SERVER_SLAVE
const SERVER_SLAVE
Definition: ezdbinterface.php:43
eZDBInterface\$AttributeVariableMap
$AttributeVariableMap
Definition: ezdbinterface.php:1833
eZDBInterface\prepareSqlQuery
prepareSqlQuery(&$fd, &$buffer)
Definition: ezdbinterface.php:242
eZDBInterface\RELATION_TABLE_BIT
const RELATION_TABLE_BIT
Definition: ezdbinterface.php:31
eZDBInterface\MIN_INT
const MIN_INT
Definition: ezdbinterface.php:57
eZDBInterface\$Port
$Port
Definition: ezdbinterface.php:1581
eZDBInterface\bitOr
bitOr( $arg1, $arg2)
Definition: ezdbinterface.php:556
eZDBInterface\$UseBuiltinEncoding
$UseBuiltinEncoding
Definition: ezdbinterface.php:1669
eZDBInterface\dropTempTableList
dropTempTableList( $tableList, $server=self::SERVER_SLAVE)
Definition: ezdbinterface.php:1358
eZDBInterface\bindVariable
bindVariable( $value, $fieldDef=false)
Definition: ezdbinterface.php:649
eZDBInterface\setErrorHandling
setErrorHandling( $errorHandling)
Definition: ezdbinterface.php:1515
eZDBInterface\transactionCounter
transactionCounter()
Definition: ezdbinterface.php:1140
eZDBInterface\arrayQuery
arrayQuery( $sql, $params=array(), $server=false)
Definition: ezdbinterface.php:681
eZDBInterface\commit
commit()
Definition: ezdbinterface.php:785
eZDBInterface\$SlavePort
$SlavePort
Definition: ezdbinterface.php:1781
eZDBInterface\BINDING_NO
const BINDING_NO
Definition: ezdbinterface.php:21
eZDBInterface\relationList
relationList( $relationType=eZDBInterface::RELATION_TABLE)
Definition: ezdbinterface.php:1181
eZDBInterface\truncateString
truncateString( $string, $maxLength, $fieldName, $truncationSuffix='')
Definition: ezdbinterface.php:1537
eZDBInterface\$IsInternalCharset
$IsInternalCharset
Definition: ezdbinterface.php:1830
eZDBInterface\supportsDefaultValuesInsertion
supportsDefaultValuesInsertion()
Definition: ezdbinterface.php:1502
eZDBInterface\errorMessage
errorMessage()
Definition: ezdbinterface.php:1378
eZDBInterface\$ErrorMessage
$ErrorMessage
Definition: ezdbinterface.php:1725
eZDBInterface\bitAnd
bitAnd( $arg1, $arg2)
Definition: ezdbinterface.php:544
eZDBInterface\__construct
__construct( $parameters)
Definition: ezdbinterface.php:64
eZDBInterface\reportError
reportError()
Definition: ezdbinterface.php:1042
eZDBInterface\invalidateTransaction
invalidateTransaction()
Definition: ezdbinterface.php:1026
eZDBInterface\dropTempTable
dropTempTable( $dropTableQuery='', $server=self::SERVER_SLAVE)
Definition: ezdbinterface.php:1347
eZDBInterface\usesBuiltinEncoding
usesBuiltinEncoding()
Definition: ezdbinterface.php:628
eZDBInterface\createTempTable
createTempTable( $createTableQuery='', $server=self::SERVER_SLAVE)
Definition: ezdbinterface.php:1335
eZDBInterface\$UseSlaveServer
$UseSlaveServer
Definition: ezdbinterface.php:1757
eZDBInterface\$IsConnected
$IsConnected
Definition: ezdbinterface.php:1685
eZDBInterface\unlock
unlock()
Definition: ezdbinterface.php:699
eZDBInterface\$SlaveServer
$SlaveServer
Definition: ezdbinterface.php:1773
eZDBInterface\eZTableList
eZTableList( $server=self::SERVER_MASTER)
Definition: ezdbinterface.php:1171
eZDBInterface\connectRetryCount
connectRetryCount()
Definition: ezdbinterface.php:458
eZDBInterface\useShortNames
useShortNames()
Definition: ezdbinterface.php:488
eZDBInterface\$InputTextCodec
$InputTextCodec
Definition: ezdbinterface.php:1661
eZDBInterface\SERVER_MASTER
const SERVER_MASTER
Definition: ezdbinterface.php:42
eZDBInterface\escapeString
escapeString( $str)
Definition: ezdbinterface.php:1284
eZDBInterface\RELATION_MASK
const RELATION_MASK
Definition: ezdbinterface.php:38
eZDBInterface\$Charset
$Charset
Definition: ezdbinterface.php:1637
eZDBInterface\supportedRelationTypeMask
supportedRelationTypeMask()
Definition: ezdbinterface.php:478
eZDBInterface\checkCharset
checkCharset( $charset, &$currentCharset)
Definition: ezdbinterface.php:229
eZDBInterface\$TimeTaken
$TimeTaken
Definition: ezdbinterface.php:1717
eZDBInterface\$errorHandling
$errorHandling
Definition: ezdbinterface.php:1828
eZDBInterface\MAX_INT
const MAX_INT
Definition: ezdbinterface.php:50
eZDBInterface\startTime
startTime()
Definition: ezdbinterface.php:404
eZDBInterface\query
query( $sql, $server=false)
Definition: ezdbinterface.php:661
eZDBInterface\beginQuery
beginQuery()
Definition: ezdbinterface.php:770
eZDBInterface\countStringSize
countStringSize( $string)
Definition: ezdbinterface.php:1559
eZDBInterface\RELATION_TABLE
const RELATION_TABLE
Definition: ezdbinterface.php:25
eZDBInterface\begin
begin()
Definition: ezdbinterface.php:710
eZDBInterface\$Password
$Password
Definition: ezdbinterface.php:1629
eZDBInterface\errorNumber
errorNumber()
Definition: ezdbinterface.php:1388
eZDBInterface\RELATION_TRIGGER_BIT
const RELATION_TRIGGER_BIT
Definition: ezdbinterface.php:33
eZDBInterface\hasAttribute
hasAttribute( $name)
Definition: ezdbinterface.php:191
eZDBInterface\socketPath
socketPath()
Definition: ezdbinterface.php:448
eZDBInterface\$TransactionIsValid
$TransactionIsValid
Definition: ezdbinterface.php:1813
eZDBInterface\ERROR_MISSING_EXTENSION
const ERROR_MISSING_EXTENSION
Definition: ezdbinterface.php:40
eZDBInterface\$SlavePassword
$SlavePassword
Definition: ezdbinterface.php:1797
eZDBInterface\$User
$User
Definition: ezdbinterface.php:1621
eZDBInterface\implodeWithTypeCast
implodeWithTypeCast( $glue, &$pieces, $type)
Definition: ezdbinterface.php:1252
eZDBInterface\$NumQueries
$NumQueries
Definition: ezdbinterface.php:1693
eZDBInterface\$ErrorNumber
$ErrorNumber
Definition: ezdbinterface.php:1733
eZDBInterface\$QueryAnalysisOutput
$QueryAnalysisOutput
Definition: ezdbinterface.php:1832
eZDBInterface\bindingType
bindingType()
Definition: ezdbinterface.php:638
eZDBInterface\endTime
endTime()
Definition: ezdbinterface.php:415
eZDBInterface\BINDING_NAME
const BINDING_NAME
Definition: ezdbinterface.php:22
eZDBInterface\RELATION_SEQUENCE
const RELATION_SEQUENCE
Definition: ezdbinterface.php:26
eZDBInterface\generateSQLINStatement
generateSQLINStatement( $elements, $columnName='', $not=false, $unique=true, $type=false)
Definition: ezdbinterface.php:1477
eZDBInterface\$OutputTextCodec
$OutputTextCodec
Definition: ezdbinterface.php:1653
eZDBInterface\lastSerialID
lastSerialID( $table=false, $column=false)
Definition: ezdbinterface.php:1274
eZDBInterface\RELATION_VIEW
const RELATION_VIEW
Definition: ezdbinterface.php:28
eZDBInterface\RELATION_TRIGGER
const RELATION_TRIGGER
Definition: ezdbinterface.php:27
eZDBInterface\connectRetryWaitTime
connectRetryWaitTime()
Definition: ezdbinterface.php:468
eZDBInterface\$DB
$DB
Definition: ezdbinterface.php:1597
eZDBInterface\setError
setError()
Definition: ezdbinterface.php:1369
eZDBInterface\concatString
concatString( $strings=array())
Definition: ezdbinterface.php:521
eZDBInterface\relationCount
relationCount( $relationType=eZDBInterface::RELATION_TABLE)
Definition: ezdbinterface.php:1161
eZDBInterface\availableDatabases
availableDatabases()
Definition: ezdbinterface.php:1399
eZDBInterface\hasRequiredServerVersion
hasRequiredServerVersion( $minVersion, $name=false)
Definition: ezdbinterface.php:570
eZDBInterface\$EndTime
$EndTime
Definition: ezdbinterface.php:1709
eZDBInterface\removeDatabase
removeDatabase( $dbName)
Definition: ezdbinterface.php:1325
eZDBInterface\isConnected
isConnected()
Definition: ezdbinterface.php:1304
eZDBInterface\attributes
attributes()
Definition: ezdbinterface.php:180
eZDBInterface\databaseClientVersion
databaseClientVersion()
Definition: ezdbinterface.php:595
eZDBInterface\$DBConnection
$DBConnection
Definition: ezdbinterface.php:1605
eZDBInterface\isCharsetSupported
isCharsetSupported( $charset)
Definition: ezdbinterface.php:605
eZDBInterface\RELATION_INDEX_BIT
const RELATION_INDEX_BIT
Definition: ezdbinterface.php:35
eZDBInterface\createDatabase
createDatabase( $dbName)
Definition: ezdbinterface.php:1315
eZDBInterface\$Server
$Server
Definition: ezdbinterface.php:1573
eZDBInterface\RELATION_SEQUENCE_BIT
const RELATION_SEQUENCE_BIT
Definition: ezdbinterface.php:32
eZDBInterface\databaseServerVersion
databaseServerVersion()
Definition: ezdbinterface.php:586
eZDBInterface\$SlaveDB
$SlaveDB
Definition: ezdbinterface.php:1765
eZDBInterface\close
close()
Definition: ezdbinterface.php:1294
eZDBInterface\$DBWriteConnection
$DBWriteConnection
Definition: ezdbinterface.php:1613
eZDBInterface\relationMatchRegexp
relationMatchRegexp( $relationType)
Definition: ezdbinterface.php:1233
eZDBInterface\version
version()
Definition: ezdbinterface.php:1441
eZDBInterface\generateTraceEntry
generateTraceEntry( $entry)
Definition: ezdbinterface.php:968
eZDBInterface\insertFile
insertFile( $path, $sqlFile, $usePathType=true)
Definition: ezdbinterface.php:294
eZDBInterface\isTransactionValid
isTransactionValid()
Definition: ezdbinterface.php:1127
eZDBInterface\$SocketPath
$SocketPath
Definition: ezdbinterface.php:1589
eZDBInterface\removeRelation
removeRelation( $relationName, $relationType)
Definition: ezdbinterface.php:1192
eZDBInterface\lock
lock( $table)
Definition: ezdbinterface.php:690
eZDBInterface\$SlaveUser
$SlaveUser
Definition: ezdbinterface.php:1789
eZDBInterface\RELATION_NONE
const RELATION_NONE
Definition: ezdbinterface.php:37
eZDBInterface\RELATION_VIEW_BIT
const RELATION_VIEW_BIT
Definition: ezdbinterface.php:34
eZDBInterface\timeTaken
timeTaken()
Definition: ezdbinterface.php:426
eZDBInterface\endTimer
endTimer()
Definition: ezdbinterface.php:390
eZDBInterface\relationName
relationName( $relationType)
Definition: ezdbinterface.php:1206
eZDBInterface\supportedRelationTypes
supportedRelationTypes()
Definition: ezdbinterface.php:497
eZDBInterface\$OutputSQL
$OutputSQL
Definition: ezdbinterface.php:1677
eZDBInterface\rollback
rollback()
Definition: ezdbinterface.php:864
eZDB\ERROR_HANDLING_STANDARD
const ERROR_HANDLING_STANDARD
Definition: ezdb.php:360
eZDB\ERROR_HANDLING_EXCEPTIONS
const ERROR_HANDLING_EXCEPTIONS
Definition: ezdb.php:361
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\printReport
static printReport( $newWindow=false, $as_html=true, $returnReport=false, $allowedDebugLevels=false, $useAccumulators=true, $useTiming=true, $useIncludedFiles=false)
Definition: ezdebug.php:1224
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZDebug\setHandleType
static setHandleType( $type)
Definition: ezdebug.php:247
eZDebug\HANDLE_NONE
const HANDLE_NONE
Definition: ezdebug.php:74
eZDir\path
static path( $names, $includeEndSeparator=false, $type=self::SEPARATOR_UNIX)
Definition: ezdir.php:237
eZExecution\setCleanExit
static setCleanExit( $hasCleanExit=true)
Definition: ezexecution.php:28
eZExecution\cleanup
static cleanup()
Definition: ezexecution.php:36
eZSys\serverVariable
static serverVariable( $variableName, $quiet=false)
Definition: ezsys.php:856
eZSys\isShellExecution
static isShellExecution()
Definition: ezsys.php:265
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: eztextcodec.php:446
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.