database.php 536 B

12345678910111213141516171819
  1. <?php
  2. require_once(realpath(dirname(__FILE__)).'/config.php');
  3. $mysqli = new mysqli(get('host'),get('user'),get('password'),get('database'));
  4. if($mysqli->connect_errno){
  5. echo "Failed to connect to MySQL: ".$mysqli->connect_error;
  6. }
  7. $mysqli->autocommit(true);
  8. function query($query,$args = Array()){
  9. global $mysqli;
  10. for ($i=0;$i<count($args);$i++){
  11. if(is_string($args[$i])){
  12. $args[$i] = $mysqli->real_escape_string($args[$i]);
  13. }else{
  14. return false;
  15. }
  16. }
  17. return $mysqli->query(vsprintf($query,$args));
  18. }
  19. ?>