PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/output/connections/dbfunctions/MySQLFunctions.php

https://gitlab.com/Lidbary/PHPRunner
PHP | 158 lines | 73 code | 19 blank | 66 comment | 7 complexity | 508dbefc54307f67b3116c5e9c03a9a1 MD5 | raw file
  1. <?php
  2. class MySQLFunctions extends DBFunctions
  3. {
  4. /**
  5. * A db connection link identifier
  6. * @type Mixed
  7. */
  8. protected $conn = null;
  9. function MySQLFunctions( $leftWrapper, $rightWrapper, $extraParams )
  10. {
  11. parent::DBFunctions( $leftWrapper, $rightWrapper, $extraParams );
  12. $this->conn = $extraParams["conn"];
  13. }
  14. /**
  15. * @param String str
  16. * @return String
  17. */
  18. public function escapeLIKEpattern( $str )
  19. {
  20. return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $str);
  21. }
  22. /**
  23. * @param String str
  24. * @return String
  25. */
  26. public function prepareString( $str )
  27. {
  28. return "'".$this->addSlashes( $str )."'";
  29. }
  30. /**
  31. * @param String str
  32. * @return String
  33. */
  34. public function addSlashes( $str )
  35. {
  36. if( useMySQLiLib() && $this->conn )
  37. {
  38. if( $this->conn )
  39. return mysqli_real_escape_string( $this->conn, $str );
  40. }
  41. // deprecated
  42. /*
  43. else if( function_exists('mysql_real_escape_string') )
  44. {
  45. mysql_real_escape_string($str);
  46. }
  47. */
  48. else
  49. {
  50. // ODBC connection, no MySQL library included
  51. return str_replace(array('\\', '\''), array('\\\\', '\\\''), $str);
  52. }
  53. }
  54. /**
  55. * @param String str
  56. * @return String
  57. */
  58. public function addSlashesBinary( $str )
  59. {
  60. if( !strlen($str) )
  61. return "''";
  62. return "0x".bin2hex($str);
  63. }
  64. /**
  65. * @param String str
  66. */
  67. public function stripSlashesBinary( $str )
  68. {
  69. return $str;
  70. }
  71. /**
  72. * adds wrappers to field name if required
  73. * @param String strName
  74. * @return String
  75. */
  76. public function addFieldWrappers( $strName )
  77. {
  78. if( substr($strName, 0, 1) == $this->strLeftWrapper )
  79. return $strName;
  80. return $this->strLeftWrapper.$strName.$this->strRightWrapper;
  81. }
  82. /**
  83. * @param String dbval
  84. * @return String
  85. */
  86. public function upper( $dbval )
  87. {
  88. return "upper(".$dbval.")";
  89. }
  90. /**
  91. * @param Mixed $val
  92. * @return String
  93. */
  94. public function addDateQuotes( $val )
  95. {
  96. return "'".$val."'";
  97. }
  98. /**
  99. * It's called for Contains and Starts with searches
  100. * @param Mixed value
  101. * @param Number type (optional)
  102. * @return String
  103. */
  104. public function field2char($value, $type = 3)
  105. {
  106. return $value;
  107. }
  108. /**
  109. * @param Mixed value
  110. * @param Number type
  111. * @return String
  112. */
  113. public function field2time($value, $type)
  114. {
  115. if( IsDateFieldType($type) )
  116. return "time(".$value.")";
  117. return $value;
  118. }
  119. /**
  120. * Get the auto generated SQL string used in the last query
  121. * @param String key (optional)
  122. * @param String table (optional)
  123. * @param String oraSequenceName (optional)
  124. * @return String
  125. */
  126. public function getInsertedIdSQL( $key = null, $table = null, $oraSequenceName = false )
  127. {
  128. return "SELECT LAST_INSERT_ID()";
  129. }
  130. /**
  131. * @param String strName
  132. * @return String
  133. */
  134. public function timeToSecWrapper( $strName )
  135. {
  136. return "TIME_TO_SEC(" . $this->addTableWrappers($strName) . ")";
  137. }
  138. }
  139. ?>