IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Convertion de Script PHP utilisant Mysql vers Postgresql [PostgreSQL]


Sujet :

PHP & Base de données

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2012
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mai 2012
    Messages : 8
    Points : 9
    Points
    9
    Par défaut Convertion de Script PHP utilisant Mysql vers Postgresql
    Dans le cadre d'un projet PFE j'ai voulu intégrer un module de chat existant utilisant (php+Ajax+mysql) (source : "http://www.dynamicajax.com/fr/AJAX_Driven_Web_Chat-271_290_291.html" )

    Le problème c'est que je suis obligé de passer par une base de donnée Postgresql.

    le script php utilisant le sgbd mysql (database.php) est le suivant :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    <?php
     
    //Make the database connection.
      db_connect() or die('Unable to connect to database server!');
     
    //You will need to replace the parameters below with the values for your database connection
    //server = the database server (usually localhost).
    //username = The user name to connect to the database.
    //password = The password to connect to the database.
      function db_connect($server = 'your server', $username = 'your db user name', $password = 'your db password', $database = 'your database name', $link = 'db_link') {
        global $$link;
     
        $$link = mysql_connect($server, $username, $password);
     
        if ($$link) mysql_select_db($database);
     
        return $$link;
      }
    //Function to handle database errors.
      function db_error($query, $errno, $error) { 
        die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[STOP]</font></small><br><br></b></font>');
      }
    //Function to query the database.
      function db_query($query, $link = 'db_link') {
        global $$link;
     
        $result = mysql_query($query, $$link) or db_error($query, mysql_errno(), mysql_error());
     
        return $result;
      }
    //Get a row from the database query
      function db_fetch_array($db_query) {
        return mysql_fetch_array($db_query, MYSQL_ASSOC);
      }
    //The the number of rows returned from the query.
      function db_num_rows($db_query) {
        return mysql_num_rows($db_query);
      }
    //Get the last auto_increment ID.
      function db_insert_id() {
        return mysql_insert_id();
      }
    //Add HTML character incoding to strings
      function db_output($string) {
        return htmlspecialchars($string);
      }
    //Add slashes to incoming data
      function db_input($string, $link = 'db_link') {
        global $$link;
     
        if (function_exists('mysql_real_escape_string')) {
          return mysql_real_escape_string($string, $$link);
        } elseif (function_exists('mysql_escape_string')) {
          return mysql_escape_string($string);
        }
     
        return addslashes($string);
      }
    Fichiers attachés Fichiers attachés

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2012
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mai 2012
    Messages : 8
    Points : 9
    Points
    9
    Par défaut de l'aide SVP
    1ere essaie :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
     
    <?php
     
     
    //Make the database connection.
      db_connect() or die('Unable to connect to database server!');
     
    //You will need to replace the parameters below with the values for your database connection
    //server = the database server (usually localhost).
    //username = The user name to connect to the database.
    //password = The password to connect to the database.
      function db_connect($server = 'your server', $username = 'your db user name', $password = 'your db password', $database = 'your database name', $link = 'db_link') {
        global $$link;
     
        $$link = pg_connect("dbname=chat host=".$server." user=".$username." password=".$password);
     
        if ($$link) // Warning: mysql_select_db() not supported.
    ;
     
        return $$link;
      }
    //Function to handle database errors.
      function db_error($query, $errno, $error) { 
        die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[STOP]</font></small><br><br></b></font>');
      }
    //Function to query the database.
      function db_query($query, $link = 'db_link') {
        global $$link;
     
        $result = pg_query($$link,$query) or db_error($query, pg_last_error() , pg_result_error());
     
        return $result;
      }
    //Get a row from the database query
      function db_fetch_array($db_query) {
        return pg_fetch_array($db_query,NULL,PGSQL_ASSOC);
      }
    //The the number of rows returned from the query.
      function db_num_rows($db_query) {
        return pg_num_rows($db_query);
      }
    //Get the last auto_increment ID.
      function db_insert_id() {
        return pg_last_oid();
      }
    //Add HTML character incoding to strings
      function db_output($string) {
        return htmlspecialchars($string);
      }
    //Add slashes to incoming data
      function db_input($string, $link = 'db_link') {
        global $$link;
     
      if (function_exists('pg_escape_string')) {
          return pg_escape_string($string, $$link);
        } elseif (function_exists('pg_escape_string')) {
          return pg_escape_string($string);
        }
     
        return addslashes($string);
      }
     
     
    ?>

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2012
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mai 2012
    Messages : 8
    Points : 9
    Points
    9
    Par défaut MySQL PHP to PostgreSQL

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. migration de mysql vers postgresql
    Par ANISSS dans le forum PostgreSQL
    Réponses: 6
    Dernier message: 18/05/2007, 15h19
  2. De MySQL vers PostGreSQL
    Par vcaudron dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 11/06/2006, 11h48
  3. [SGBD] Migration de mysql vers PostgreSQL ?
    Par haffouff dans le forum SQL Procédural
    Réponses: 12
    Dernier message: 25/05/2006, 15h29
  4. conversion mysql vers postgresql
    Par backus dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 04/07/2005, 18h42
  5. Migrer de MySQL vers PostgreSQL
    Par Acti dans le forum PostgreSQL
    Réponses: 9
    Dernier message: 25/02/2005, 14h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo