Strumenti Utente

Strumenti Sito


software:php

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Entrambe le parti precedenti la revisione Revisione precedente
Prossima revisione
Revisione precedente
software:php [2019/12/11 22:01]
stefano
software:php [2023/04/17 14:25] (versione attuale)
Linea 1: Linea 1:
 +===== $_SESSION =====
 +
 +https://www.html.it/pag/62981/gestire-le-sessioni-in-php/ \\
 +
 +===== classi php =====
 +
 +qui informazioni: https://www.html.it/pag/18341/creare-le-classi/ \\
 +
 +dichiarazione della classe \\
 +  class MyClass {
 +       // implementazione della classe MyClass...
 +  }
 +
 +  class MyClass {
 +      // variabili membro
 +      public $a = 10;
 +      public $b = 20;
 +      // funzioni
 +      public function sayHello() {
 +              echo "Hello!";
 +      }
 +  }
 +
 +uso della classe\\
 +  $myClass_1 = new MyClass();
 +  // stampa "Hello!"
 +  $myClass_1->sayHello();
 +  // stampa 10
 +  echo $myClass_1->a;
 +
 +===== autenticazione =====
 +
 +https://www.codeofaninja.com/2013/03/php-login-script.html \\
 +
 +https://www.targetweb.it/script-login-utente-in-php-e-mysql-sicuro/ \\
 +
 +https://phppot.com/php/multi-select-dropdown-filter-in-php-with-database-search/ \\
 +
 +https://www.targetweb.it/form-ricerca-avanzata-php-mysql/
 +
 +https://911-code.com/php-mysql-inserire-la-data-in-formato.html
 +===== INFO =====
 +per avere info su php\\
 +https://www.w3schools.com/php/php_form_validation.asp
 +
 ===== PHP ===== ===== PHP =====
 il casino è che dalla debian 9 è cambiata la versione di default del php che dalla 5 è passata alla 7.\\ il casino è che dalla debian 9 è cambiata la versione di default del php che dalla 5 è passata alla 7.\\
Linea 24: Linea 69:
   grant all privileges on database.* to 'nomeutentespecifico'@'localhost' identified by 'passwordutente';   grant all privileges on database.* to 'nomeutentespecifico'@'localhost' identified by 'passwordutente';
      
 +altro file:\\
 +<file php ins.php>
 +<html>
 +<head>
 +</head>
 +<body>
 +
 +<?php
 +
 +$dbname = 'tato';
 +$dbuser = 'tato';
 +$dbpass = 'tatone';
 +$dbhost = 'localhost';
 +
 +$link = new mysqli($dbhost, $dbuser, $dbpass, $dbname) ;
 +// Check connection
 +            if ($link->connect_error) {
 +               die("Connection failed: " . $link->connect_error);
 +            }
 +
 +//mysqli_select_db($dbname)
 +//or die("Could not open the db '$dbname'");
 +
 +
 +
 +//$name = $_POST['name'];
 +//$address = $_POST['address'];
 +
 +
 +// $toinsert = "INSERT INTO anagrafica (name, address) VALUES ('$name','$address')";
 +$sql = "INSERT INTO anagrafica (name, address) VALUES ('".$_POST["name"]."','".$_POST["address"]."')";
 +
 +
 +
 +
 +if (mysqli_query($link, $sql)) {
 +               echo "New record created successfully";
 +            } else {
 +               echo "Error: " . $sql . "" . mysqli_error($link);
 +            }
 +            $link->close();
 +
 +
 +
 +?>
 +test
 +</body>
 +</html>
 +
 +</file>
 +
 +form html\\
 +
 +<file html form.html>
 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
 +Transitional//EN"
 +"http://www.w3.org/TR/html4/loose.dtd">
 +<html>
 +
 +<head>
 +<title>PAGINA CARICAMENTO DATI</title>
 +</head>
 +
 +<body>
 +<table border="0">
 +  <tr>
 +    <td align="center">Inserisci i dati richiesti</td>
 +  </tr>
 +  <tr>
 +    <td>
 +      <table>
 +        <form method="post" action="creadiretto.php">
 +        <tr>
 +          <td>Nome</td>
 +          <td><input type="text" name="name" size="20">
 +          </td>
 +        </tr>
 +        <tr>
 +          <td>Indirizzo</td>
 +          <td><input type="text" name="address" size="40">
 +          </td>
 +        </tr>
 +        <tr>
 +          <td></td>
 +          <td align="right"><input type="submit"
 +          name="submit" value="Sent"></td>
 +        </tr>
 +        </form>
 +        </table>
 +      </td>
 +    </tr>
 +</table>
 +</body>
 +</html>
 +</file>
 +
 +Per creare una tabella da riga di comando:\\
 +>CREATE TABLE person(prodp_id INT NOT NULL AUTO_INCREMENT, nomep VARCHAR(20)NOT NULL, PRIMARY KEY (prodp_id)) ENGINE = InnoDB; 
 +
 +pagina da verificare per inserimento tabella:\\
 +<file html ins.html>
 +    <html>
 +       <head>
 +          <title>Create a MariaDB Table</title>
 +       </head>
 +     
 +       <body>
 +          <?php
 +             $dbhost = 'localhost';
 +             $dbuser = 'tato';
 +             $dbpass = 'tatone';
 + $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
 +     
 +             if(! $conn ){
 +                die('Could not connect: ' . mysql_error());
 +             }
 +             echo 'Connected successfully<br />';
 +     
 +             $sql = "CREATE TABLE products_tbl( ".
 +                "product_id INT NOT NULL AUTO_INCREMENT, ".
 +                "product_name VARCHAR(100) NOT NULL, ".
 +                "product_manufacturer VARCHAR(40) NOT NULL, ".
 +                "submission_date DATE, ".
 +                "PRIMARY KEY ( product_id )); ";
 +     
 +             mysqli_select_db($conn, 'test' );
 +             $retval = mysqli_query( $conn,$sql );
 +     
 +             if(! $retval ) {
 +                die('Could not create table: ' . mysql_error());
 +             }
 +             echo "Table created successfully\n";
 +     
 +             mysqli_close($conn);
 +          ?>
 +       </body>
 +    </html>
 +</file>
 +
 +
 +Informazioni tipiche per mariadb, andrà creata una pagina apposta:\\
 +Quando si crea un database per poterlo gestire da altre interfacce ad esempio php o altre API o altro, è bene creare un utente specifico che abbia i diritti sul database che non sia root per creare tabelle, inserire, modificare e altro. Si fa con il seguente comando che crea anche l'utente appunto.\\
 +>GRANT ALL PRIVILEGES ON nomedatabase.* TO 'nomeutentechestocreando'@'localhost' IDENTIFIED BY 'passworddelnuovoutente';
 +
 +in openstack viene creato anche il seguente accesso:\\
 +>>GRANT ALL PRIVILEGES ON nomedatabase.* TO 'nomeutentechestocreando'@'%' IDENTIFIED BY 'passworddelnuovoutente';
 +
 +
 +ATTENZIONE.\\
 +Su internet si trovano ancora un sacco di riferimenti a vecchie versioni di php che usano funzioni ormai dprecate.\\
 +Ad esempio mysql_connect() o mysqli_connect() \\
 +è bene usare la seconda versione in quanto è più nuova più versatile e recente.\\
 +Non so spiegare ancora il perchè ma è così. QUindi evitare tutte le altre guide.\\
  
 +===== proxmox =====
 +ho avuto esperienza di proxmox che dopo aver installato apache e mariadb spembrava installato completamente php invece mancava libapache2-mod-php \\
 +sono stato 2 ore a smanettare per poi scoprire che mancava quello. quindi okkio! \\
software/php.1576098066.txt.gz · Ultima modifica: 2023/04/17 14:25 (modifica esterna)