Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. DbConnect dlTask = new DbConnect();
  2.  
  3. if (tabActifChoisis.length == 3) {
  4.  
  5. String pa = tabActifChoisis[0];
  6. dlTask.execute(sexe, age, formule, base, pa);
  7. }
  8.  
  9. public class DbConnect extends AsyncTask<String, Void, String> {
  10.  
  11. protected String doInBackground(String... param) {
  12.  
  13. ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
  14.  
  15. nameValuePairs.add(new BasicNameValuePair("sexe", param[0].toString()));
  16. nameValuePairs.add(new BasicNameValuePair("age", param[1].toString()));
  17. nameValuePairs.add(new BasicNameValuePair("formule", param[2].toString()));
  18. nameValuePairs.add(new BasicNameValuePair("base", param[3].toString()));
  19. nameValuePairs.add(new BasicNameValuePair("pa", param[4].toString()));
  20.  
  21. try {
  22. HttpClient client = new DefaultHttpClient();
  23. HttpPost httppost = new HttpPost("http://10.0.2.2/AppBdd.php");
  24. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  25. client.execute(httppost);
  26. } catch (Exception e) {
  27. Log.e("log_tag", "Error in http connection " + e.toString());
  28. }
  29.  
  30. return null;
  31. }
  32.  
  33. }
  34.  
  35. <?php
  36. require_once ("rees.php");
  37.  
  38. $pdo = PdoGsb::getPdoGsb();
  39.  
  40.  
  41. $sexe = $_REQUEST['sexe'];
  42. $age = $_REQUEST['age'];
  43. $form = $_REQUEST['formule'];
  44. $base = $_REQUEST['base'];
  45. $pa = $_REQUEST['pa'];
  46.  
  47. $pdo->setClient($sexe, $age, $form, $base, $pa);
  48.  
  49. <?php
  50.  
  51. class PdoGsb{
  52. private static $serveur='mysql:host=localhost';
  53. private static $bdd='dbname=testdepeau';
  54. private static $user='root';
  55. private static $mdp='';
  56. private static $monPdo;
  57. private static $monPdoGsb=null;
  58.  
  59. private function __construct(){
  60. PdoGsb::$monPdo = new PDO(PdoGsb::$serveur.';'.PdoGsb::$bdd, PdoGsb::$user, PdoGsb::$mdp);
  61. PdoGsb::$monPdo->query("SET CHARACTER SET utf8");
  62. PdoGsb::$monPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  63. }
  64.  
  65. public function __destruct(){
  66. PdoGsb::$monPdo = null;
  67. }
  68.  
  69. public static function getPdoGsb(){
  70. if(PdoGsb::$monPdoGsb==null){
  71. PdoGsb::$monPdoGsb= new PdoGsb();
  72. }
  73. return PdoGsb::$monPdoGsb;
  74. }
  75.  
  76. public function setClient($sexe, $age, $form, $base, $pa){
  77. $req="INSERT INTO client (formule, sexe, age, base, pa)
  78. VALUES
  79. ('$form', '$sexe', '$age', '$base', '$pa');";
  80. $res2= PdoGsb::$monPdo->exec($req);
  81. }
  82.  
  83. }
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement