Tags: mysql,php

Sort by: Date / Title /

  1. 10 years ago by jacinmontava
    1. <?php
    2.  
    3. $dbhost = "servidor"; $dbuser = "usuario"; $dbpassword = "clave"; $dbname = "base_de_datos";
    4. mysql_connect($dbhost,$dbuser,$dbpassword);
    5. $tablas = mysql_list_tables($dbname);
    6.  
    7. while (list($tabla) = mysql_fetch_row($tablas)) {
    8. echo $tabla."<br />";
    9. } ?>
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1378"></script>
  2. 10 years ago by sx
    1. DATUM=`date '+%Y-%m-%d'`
    2. mysqldump -u USER --password=PASSWORD DATABASE TABLE > /home/backup/db.sql
    3. gzip /home/backup/db.sql
    4. mv /home/backup/db.sql.gz /home/backup/db-${DATUM}.sql.gz
    5. find /home/backup/ -mtime +2 -type f -print0 | xargs -0 rm
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1069"></script>
  3. 11 years ago by jacinmontava
    Con esta funcion extraemos un dato en concreto de la BD tan solo llamando a la funcion y pasandole la tabla, el campo que queremos y la id.
    1. function dime_datos($tabla, $campo, $id_recibida)
    2. {
    3.    $link = conectarse();
    4.    $consulta_sql = "SELECT $campo FROM $tabla WHERE id = '$id_recibida'";
    5.    $consultar = mysql_query($consulta_sql, $link);
    6.    return mysql_result($consultar, 0);
    7. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/627"></script>
  4. sponsorised links
  5. 11 years ago by jacinmontava
    1. $localhost = "localhost";
    2. $usuario = "nombre usuario BD";
    3. $password = "password BD";
    4. $nombreBD = "nombre BD"
    5.  
    6. function conectarse()
    7. {
    8.    if (!($link=mysql_connect($localhost,$usuario,$password)))
    9.    {
    10.       echo "Error conectando a la base de datos.";
    11.       exit();
    12.    }
    13.    if (!mysql_select_db($nombreBD,$link))
    14.    {
    15.       echo "Error seleccionando la base de datos.";
    16.       exit();
    17.    }
    18.    return $link;
    19. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/623"></script>
  6. 11 years ago by jacinmontava and saved by 1 other
    1. mysql_query("INSERT INTO table (nom_table) values ('ex')");
    2.    $ultima_idmysql_insert_id();
    3.    echo $ultima_id;
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/602"></script>
  7. 11 years ago by xillon and saved by 1 other
    1. <?php
    2.  
    3.    mysql_query("INSERT INTO table (nom_table) values ('ex')");
    4.    $dernier_idmysql_insert_id();
    5.    echo $dernier_id;
    6.  
    7. ?>
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/562"></script>
  8. 11 years ago by xillon
    1. function selectTable($nomtable, $where = NULL, $order = NULL)
    2.          {
    3.             $sql = "SELECT * FROM $nomtable";
    4.             if ( $where !== NULL ) $sql .= " WHERE $where";
    5.             if ($order !== NULL)$sql.=" ORDER BY $order ";
    6.            
    7.             $query=mysql_query($sql);
    8.            
    9.             $ret = array();
    10.             while ( $donnee = mysql_fetch_assoc($query))
    11.             {
    12.                $ret[] = $donnee;
    13.             }
    14.             return $ret;
    15.          }
    16.          
    17.          function sqlSelect($sqlDonnee, $nomCol, $valCol)
    18.          {
    19.             for($i = 0 ; $i<count($sqlDonnee) ; $i++)
    20.             {
    21.                $selectDonee["name"][$i] = $sqlDonnee[$i][$nomCol];
    22.                $selectDonee["value"][$i] = $sqlDonnee[$i][$valCol];
    23.             }
    24.          return $selectDonee;
    25.          }
    26.          
    27.          function htmlSelect($nom, $options, $selected = NULL, $css = NULL)
    28.          {
    29.             $select  = "<select name=\"".htmlentities($nom)."\"";
    30.             if ( $css !== NULL )
    31.                $select .= " $css>";
    32.             else
    33.                $select .= ">";
    34.  
    35.             for($i = 0 ; $i<count($options["name"]) ; $i++)
    36.             {
    37.                if ( $selected !== NULL && $selected == $options["value"][$i] )
    38.                   $select .= "<option value=\"".$options["value"][$i]."\" selected=\"selected\">".$options["name"][$i]."</option>\n";
    39.                else
    40.                   $select .= "<option value=\"".$options["value"][$i]."\">".$options["name"][$i]."</option>\n";
    41.             }
    42.             $select .= "</select>\n";
    43.  
    44.             return $select;
    45.          }
    46.  
    47. /*** Exemple utilisation ***/
    48. /* <option selected> par defaut pour le pays ayant l'id 72 */
    49.          $paysSelect = isset($_POST["pays"]) ? ($_POST["pays"]) : ("72");
    50.          
    51.          $selectPays=selectTable("pays");
    52.          $pays=sqlSelect($selectPays,"nom","id");         
    53.          echo htmlSelect("id", $pays, $paysSelect); // on construit notre <select>
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/218"></script>

First / Previous / Next / Last / Page 1 of 1 (7 posteets)