Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*from mysqli to PDO
- Avant en MSQLI fallait faire ca pour la connection :
- ------------------------------------------------------------------
- $BD_serveur = "localhost";
- $BD_utilisateur = "root";
- $BD_motDePasse = "";
- $BD_base = "animehun_site";
- $url_base = "/oioiji/v1/";
- $mysqli = new mysqli($BD_serveur,$BD_utilisateur, $BD_motDePasse,$BD_base);
- if ($mysqli->connect_errno) {
- printf("Échec de la connexion : %s\n", $mysqli->connect_error);
- exit();
- }
- $mysqli->set_charset("utf8");
- ------------------------------------------------------------------
- Maintenant en PDO ca ce passe comme cela :
- ------------------------------------------------------------------
- $errors = array();
- $RemoteIP = $_SERVER['REMOTE_ADDR'];
- $options = array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- );
- try {
- $pdo = new PDO('mysql:host=localhost;dbname=Nom_Database', 'COMPTE_SQL', 'PASSWORD',$options); //Test de ce co Si c'est en local !
- }
- catch(Exception $e){}
- finally { //si il a pas réussi a ce co en local (donc il est sur un dédiers)
- if (isset($e)){
- try {
- $pdo = new PDO('mysql:host=localhost;dbname=Nom_Database', 'COMPTE_SQL', 'PASSWORD',$options); //Remote !
- }
- catch(Exception $e2){
- //print_r($e); // a decomment si tu veux les erreures
- }
- finally {
- if (isset($e2)){
- //de la tu peux faire un echo ou print des erreures ;)
- exit;
- }
- }
- }
- }
- ------------------------------------------------------------------
- Maintenant en utilisation MSSQLI tu fait ecla :
- ------------------------------------------------------------------
- $sql = " SELECT * FROM news WHERE date > '".$daten."' AND date <= '".$dateplus."'ORDER by date DESC";
- if(!$result = $mysqli->query($sql)){
- die('There was an error running the query [' . $db->error . ']');
- }
- $datebdd1 = '';
- while($row = $result->fetch_assoc()){
- $ = substr($row['date'],0,-9);
- $titreEpi = $row['titre'];
- $episode = $row['episode'];
- $numeroEpi = $row['numero'];
- $version = $row['version'];
- $saison = $row['saison'];
- $urlimg = $row['urlimg'];
- $url = $row['url']; //pas besoin de deux fois la variable ici au passage
- $url = str_replace('/anime/',$url_base.'visio/',$url);
- $newser = $row['ajouteur'];
- $render = $row['render'];
- $text = $row['text'];
- $comment = $row['comment'];
- $etat = $row['etat'];
- }
- ------------------------------------------------------------------
- Sous PDO ca se passera comme ca :
- ------------------------------------------------------------------
- $CommandName = $pdo->prepare("SELECT * FROM news WHERE date > '$daten' AND date <= '$dateplus' ORDER by date DESC");
- $CommandName->execute();
- if ($CommandName->rowCount() > 0) {
- while ($row = $CommandName->fetch(PDO::FETCH_ASSOC)){
- $datebdd = substr($row['date'],0,-9);
- $titreEpi = $row['titre'];
- $episode = $row['episode'];
- $numeroEpi = $row['numero'];
- $version = $row['version'];
- $saison = $row['saison'];
- $urlimg = $row['urlimg'];
- $url = str_replace('/anime/',$url_base.'visio/',$row['url']);
- $newser = $row['ajouteur'];
- $render = $row['render'];
- $text = $row['text'];
- $comment = $row['comment'];
- $etat = $row['etat'];
- }
- }
- ------------------------------------------------------------------
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment