Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2013
    Messaggi
    8

    Connessione Database MySQL

    Salve,sto testando lo script presente su questo sito HTML.it, precisamente quello della Guida Pratica PHP ma non riesco a collegarmi al Database MySQL , sto utilizzando come ambiente XAMPP.

    Questa è la pagina index.php

    Codice PHP:
    <?php

    $limit 
    5// articoli per pagina

    $mysql = new mysqli(‘localhost’‘root’‘html_it_articles’);
    if(!
    $mysql)
    {
        die(
    “Errore di connessione al databaseimpossibile procedere”);
    }

    $result $mysql->query(“SELECT COUNT(*) AS tot FROM articles”)->fetch_assoc();

    $page = isset($_GET['p']) ? $_GET['p'] : 1;
    $totals $result['tot'];
    $totals_pages ceil($totals $limit);

    $articles $mysql->query(
        SELECT
            AR
    .id AS id,
            
    AR.title AS title,
            
    CONCAT(SUBSTR(AR.article1200),  ‘ …’) AS content,
            
    CONCAT(AU.surname‘ ‘AU.name) AS author
        FROM
            articles AR
    ,
            
    authors AU
        WHERE
            AR
    .author_id AU.id
        ORDER BY id DESC
        LIMIT “
    .(($page – 1) * $limit).,.$limit);
    ?>
    <html>
        <head>
            <title>Articoli</title>
        </head>
        <body>
            <ul>[*]<a href=”index.php”>Lista articoli</a>[*]<a href=”insert.php”>Inserisci un articolo</a>[/list]
            

    Articoli totali: <?php echo $totals?></p>
            <table width=”500px”>
                <?php
                
    while($article $articles->fetch_assoc())
                {
                    
    printf(<tr>
                            <
    td>%d. <a href=”show.php?id=%d”>%s</a> (%s) </td>
                        </
    tr>
                        <
    tr>
                            <
    td>

    %
    s</p></td>
                        </
    tr>
                        <
    tr>
                            <
    td><hr /></td>
                        </
    tr>,
                        
    $article['id'],
                        
    $article['id'],
                        
    $article['title'],
                        
    $article['author'],
                        
    $article['content']
                        );
                }
                
    ?>
            </table>
            

    Pagina <?php echo $page?> di <?php echo $totals_pages?> 

            <?php
            
    if($page – 1 0)
            {
                echo 
    [url="”?p=’.($page"]< prev[/url] | ;
            }else
            {
                echo 
    prev ;
            }
            if(
    $page <= $totals_pages)
            {
                        echo 
    [url="”?p=’.($page"]next >[/url];
            }else
            {
                        echo 
    ‘next >;
            }
            
    ?>
            </p>
        </body>
    </html>
    Io ho modificato la stringa per la connessione in questo modo :
    codice:
    $mysql = new mysqli(‘localhost’, ‘root’, 123456 , ‘html_it_articles’);
    ma mi viene restituito il seguente errore:
    Parse error: syntax error, unexpected 'di' (T_STRING) in C:\xampp\htdocs\3mweb\html_it\guida_pratica\sito\i ndex.php on line 8
    Dove sto sbagliando ?

    Grazie

  2. #2
    Utente bannato
    Registrato dal
    Dec 2012
    Messaggi
    679
    Mancano gli '

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2013
    Messaggi
    8

    Apici

    Originariamente inviato da franzauker2.0
    Mancano gli '
    Ho sempre lo stesso errore :
    codice:
    $mysql = new mysqli(‘localhost’, ‘root’, ‘09121965’, ‘html_it_articles’);

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.