Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DbConnect dlTask = new DbConnect();
- if (tabActifChoisis.length == 3) {
- String pa = tabActifChoisis[0];
- dlTask.execute(sexe, age, formule, base, pa);
- }
- public class DbConnect extends AsyncTask<String, Void, String> {
- protected String doInBackground(String... param) {
- ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
- nameValuePairs.add(new BasicNameValuePair("sexe", param[0].toString()));
- nameValuePairs.add(new BasicNameValuePair("age", param[1].toString()));
- nameValuePairs.add(new BasicNameValuePair("formule", param[2].toString()));
- nameValuePairs.add(new BasicNameValuePair("base", param[3].toString()));
- nameValuePairs.add(new BasicNameValuePair("pa", param[4].toString()));
- try {
- HttpClient client = new DefaultHttpClient();
- HttpPost httppost = new HttpPost("http://10.0.2.2/AppBdd.php");
- httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- client.execute(httppost);
- } catch (Exception e) {
- Log.e("log_tag", "Error in http connection " + e.toString());
- }
- return null;
- }
- }
- <?php
- require_once ("rees.php");
- $pdo = PdoGsb::getPdoGsb();
- $sexe = $_REQUEST['sexe'];
- $age = $_REQUEST['age'];
- $form = $_REQUEST['formule'];
- $base = $_REQUEST['base'];
- $pa = $_REQUEST['pa'];
- $pdo->setClient($sexe, $age, $form, $base, $pa);
- <?php
- class PdoGsb{
- private static $serveur='mysql:host=localhost';
- private static $bdd='dbname=testdepeau';
- private static $user='root';
- private static $mdp='';
- private static $monPdo;
- private static $monPdoGsb=null;
- private function __construct(){
- PdoGsb::$monPdo = new PDO(PdoGsb::$serveur.';'.PdoGsb::$bdd, PdoGsb::$user, PdoGsb::$mdp);
- PdoGsb::$monPdo->query("SET CHARACTER SET utf8");
- PdoGsb::$monPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- public function __destruct(){
- PdoGsb::$monPdo = null;
- }
- public static function getPdoGsb(){
- if(PdoGsb::$monPdoGsb==null){
- PdoGsb::$monPdoGsb= new PdoGsb();
- }
- return PdoGsb::$monPdoGsb;
- }
- public function setClient($sexe, $age, $form, $base, $pa){
- $req="INSERT INTO client (formule, sexe, age, base, pa)
- VALUES
- ('$form', '$sexe', '$age', '$base', '$pa');";
- $res2= PdoGsb::$monPdo->exec($req);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement