sql.php 881 B

123456789101112131415161718192021222324252627
  1. <?PHP
  2. include_once("config.php");
  3. function connectSQL()
  4. {
  5. global $sql_user,$sql_password,$sql_server,$sql_db;
  6. $sqlConnection = mysql_pconnect($sql_server,$sql_user,$sql_password); //This is a connection to a local SQL server.
  7. if (!$sqlConnection)
  8. die("Could not connect to SQL DB: " . mysql_error());
  9. if (!mysql_select_db($sql_db,$sqlConnection))
  10. die('Could not select DB: ' . mysql_error());
  11. return $sqlConnection;
  12. }
  13. function sql_query(/*format,...*/)
  14. {
  15. $sqlConnection = connectSQL();
  16. $params = func_get_args();
  17. $query = $params[0];
  18. $args = Array();
  19. for ($i=1;$i<count($params);$i++)
  20. $args[$i-1] = mysql_real_escape_string($params[$i],$sqlConnection);
  21. $result = mysql_query(vsprintf($query,$args),$sqlConnection);
  22. if (!$result)
  23. die(mysql_error() . "Query: " . vsprintf($query,$args));
  24. return $result;
  25. }
  26. ?>