Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. <?php
  2.  
  3. namespace YetAnotherPanel;
  4.  
  5. final class Engine extends Core implements i_Engine
  6. {
  7.  
  8. private $mySQL_Server = '',
  9. $mySQL_Username = '',
  10. $mySQL_Password = '',
  11. $mySQL_Database = '',
  12. $mySQL_Link = '',
  13. $mySQL_Connected = false;
  14.  
  15. protected static $params = array(), $queryCount = 0, $rawQuery = '';
  16.  
  17. final public function __construct( array $dbArray )
  18. {
  19.  
  20. $this->mySQL_Server = $dbArray['Server'];
  21. $this->mySQL_Username = $dbArray['Username'];
  22. $this->mySQL_Password = $dbArray['Password'];
  23. $this->mySQL_Database = $dbArray['Database'];
  24.  
  25. try
  26. {
  27.  
  28. $this->connect();
  29.  
  30. }
  31. catch( Error $e ){}
  32.  
  33. $this->query('SELECT id FROM users WHERE id = {0, i} AND username = {1}', array( 'Boobs', '' ) );
  34.  
  35. }
  36.  
  37. final public function connect()
  38. {
  39.  
  40. if( !$this->mySQL_Link = @$this->functions['connect']( $this->mySQL_Server, $this->mySQL_Username, $this->mySQL_Password ) )
  41. {
  42.  
  43. throw new Error('Can not connect to mySQL server. <br /><br />'. $this->functions['error'] );
  44.  
  45. }
  46.  
  47. if( !@$this->functions['select_db']( $this->mySQL_Database, $this->mySQL_Link ) )
  48. {
  49.  
  50. throw new Error('Can not connect to database. <br /><br />'. $this->functions['error'] );
  51.  
  52. }
  53.  
  54. unset( $mySQL_Server, $mySQL_Username, $mySQL_Password, $mySQL_Database );
  55.  
  56. $this->mySQL_Connected = true;
  57.  
  58. }
  59.  
  60. final public static function rawQuery($Query, $params = array() )
  61. {
  62.  
  63. $find = '/\{([0-9]+)(,)?( )?([ibds]{1})?\}/s';
  64.  
  65. if( preg_match( $find, $Query ) )
  66. {
  67.  
  68. self::$params = $params;
  69.  
  70. while( (bool) (int) preg_match( $find, $Query ) )
  71. {
  72.  
  73. $Query = preg_replace_callback(
  74.  
  75. $find,
  76. create_function('$ma', 'return YetAnotherPanel\Engine::returnParam( $ma[ 1 ], $ma[ 4 ] );' ),
  77. $Query
  78.  
  79. );
  80.  
  81. }
  82.  
  83. self::$rawQuery = $Query;
  84.  
  85. try
  86. {
  87.  
  88. $Query = @mysql_query($Query);
  89.  
  90. if( @mysql_error() )
  91. {
  92.  
  93. throw new Error('Could not execute mySQL query. <br /><br /><strong>Raw Query</strong>: <br /><br />'.self::$rawQuery . ' <br /><br /><strong>Error</strong>: <br /><br />' . mysql_error() );
  94.  
  95. }
  96.  
  97. }
  98. catch( Error $e ){}
  99.  
  100. return $Query;
  101.  
  102.  
  103. }
  104.  
  105. }
  106.  
  107. final public static function returnParam( $arrayNumber = '', $arrayType = 's' )
  108. {
  109.  
  110. $param = self::$params[ $arrayNumber ];
  111.  
  112. switch( $arrayType )
  113. {
  114.  
  115. default:
  116. case 's':
  117.  
  118. $param = mysql_real_escape_string( $param );
  119.  
  120. break;
  121.  
  122. case 'i':
  123.  
  124. if( !is_numeric( $param ) )
  125. {
  126.  
  127. return '"0"';
  128.  
  129. }
  130.  
  131. break;
  132.  
  133. case 'b':
  134.  
  135. if( !is_bool( $param ) )
  136. {
  137.  
  138. return '"0"';
  139.  
  140. }
  141.  
  142. break;
  143.  
  144. case 'd':
  145.  
  146. if( !is_double( $param ) )
  147. {
  148.  
  149. return '"0"';
  150.  
  151. }
  152.  
  153.  
  154. break;
  155.  
  156. }
  157.  
  158. return '"'. self::$params[ $arrayNumber ] . '"';
  159.  
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement