2016-04-09 10 views
7

Ho creato un file php ed è sul mio server. Dopo aver aperto il file php da chrome, viene visualizzato "Impossibile trovare il database".Impossibile trovare il database

<?php 

    $dbhost = "fdb7.biz.nf"; 
    $database = "2065616_knurum"; 
    $username = "2065616_knurum"; 
    $dbpass = "XXXXXXXXX"; 

    mysqli_connect($dbhost, $username, $dbpass, $database); 

    @mysql_select_db($database) or die("Unable to find database"); 

    $name = isset($_GET["name"]) ? $_GET["name"] : ''; 

    $message = isset($_GET["message"]) ? $_GET["message"] : ''; 


    $query = "INSERT INTO test VALUES ('', '$name', '$message')"; 

    mysql_query($query) or die (mysql_error("error")); 

    mysql_close(); 

    echo"hello"; 
    ?> 

Dopo alcuni commenti aiutanti, qui è la soluzione giusta, e ti worked.thank per tutti gli aiutanti risposto.

$dbhost = "fdb7.biz.nf"; 
$database = "2065616_knurum"; 
$username = "2065616_knurum"; 
$dbpass = "XXXXXXXX"; 

$link = mysqli_connect($dbhost, $username, $dbpass, $database); 

if (!$link) { 
    echo "Error: Unable to connect to MySQL." . PHP_EOL; 
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; 
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; 
    exit; 
} 


$name = isset($_GET["name"]) ? $_GET["name"] : ''; 

$message = isset($_GET["message"]) ? $_GET["message"] : ''; 

$query = "INSERT INTO test VALUES ('', '$name', '$message')"; 

mysqli_query($link, $query) or die (mysqli_error("error")); 


echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL; 
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL; 
mysqli_close($link); 
?> 
+5

hai controllato le tasche ??? retro del divano ??? sotto il seggiolino auto ???? potrebbe essere il nascondiglio del tuo codice perché non riesco a trovarlo? così come le prove che hai provato a risolvere il problema .... mancano tutti !!! – gavgrif

+0

@gavgrif grazie per il tuo impegno. ora il codice non è nascosto. –

+0

Ciao, potresti controllare il verde alla mia risposta se è d'aiuto –

risposta

2
1) check your database spelling. 
2) have you given all the required privileges to user? 
3) username and password is correct ? 
6

Prova questo riferimento da http://php.net/manual/en/function.mysqli-connect.php

<?php 

$dbhost = "fdb7.biz.nf"; 
$database = "2065616_knurum"; 
$username = "2065616_knurum"; 
$dbpass = "XXXXXXXXX"; 

$link = mysqli_connect($dbhost, $username, $dbpass, $database); 

if (!$link) { 
    echo "Error: Unable to connect to MySQL." . PHP_EOL; 
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; 
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; 
    exit; 
} 

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL; 
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL; 

mysqli_close($link); 
+0

Grazie. È un grande aiuto –

2

si stia mescolando l'uso delle librerie mysql e mysqli.

scelto la seconda un bastone con esso

cioè

@mysql_select_db($database) or die("Unable to find database"); 

dovrebbe essere

@mysqli_select_db($database) or die("Unable to find database"); 
2

In primo luogo, non è possibile mescolare mysql_* funzioni e mysqli_* funzioni, il secondo è migliore come mysql_* ha già stato deprecato.

$conn = mysqli_connect($dbhost, $username, $dbpass, $database); 

$query = "INSERT INTO test VALUES ('', '$name', '$message')"; 

mysqli_query($conn, $query) or die (mysqli_error("error")); 

mysqli_close(); 

Inoltre, non si deve sopprimere i messaggi di errore:

@mysqli_select_db($database) or die("Unable to find database"); 

Rimuovere @ per abilitare la segnalazione degli errori. È molto utile per diagnosticare errori di sintassi.