Φωτογραφία Βασίλειος Καπελέρης
Ζήτημα Β2
από Βασίλειος Καπελέρης - Saturday, 26 May 2012, 9:31 PM
 
Καλησπέρα !!

Θα ηθελα την βοηθεια σας γιατι έχω κολλήσει στο Β2...

Ενώ συνδέομαι στον υπολογιστή υπηρεσίας localhost δεν μπορώ να συνδεθώ
στην βάση azulmediadb και να τραβήξω τις εγγραφές...

Παρακάτω παραθέτω τον κώδικα php >>

<?php

DEFINE('DB_HOST','localhost');
$lch = @mysqli_connect(DB_HOST);
if($lch == TRUE )
{
print "the connection to the server was succesful<br/>";
print "<br/>";
}else
{
print "the connection to the server was not succesful<br/>";
print "<br/>";
@mysqli_connect_error();
}

DEFINE('DB_NAME','azulmediadb');
$dbc = @mysqli_select_db($lch,DB_NAME);
if($dbc == TRUE){
print "the connection to the database was succesful<br/>";
print "<br/>";
}else
{
print "the connection to the database was not succesful<br/>";
print "<br/>";
}

$q = "SELECT*FROM style";
$results = @mysqli_query($lch,$q);

if($results) {
$rows = @mysqli_num_rows($results);
print "Υπάρχουν $rows γραμμές αποτελέσματων<br/>";
print "<br/>";
}else{
print "there was an error with the execution of the SQL Query<br/>";
print "<br/>";
}

while($retrec = mysqli_fetch_array($results,MYSQLI_ASSOC))
{
$id = $retrec['id'];
$color = $retrec['color'];
$url = $retrec['URL'];
}

?>

Τι στο καλό κάνω λάθος;;


 
Φωτογραφία Βασίλειος Καπελέρης
Απάντηση: Ζήτημα Β2
από Βασίλειος Καπελέρης - Sunday, 27 May 2012, 6:47 AM
 
Τελικά βρήκα τι έκανα λάθος...

<?php

DEFINE('DB_HOST','localhost');
DEFINE('DB_USER','root');
$lch = @mysqli_connect(DB_HOST,DB_USER,NULL);
if($lch == TRUE )
{
print "the connection to the server was successful<br/>";
print "<br/>";
}else
{
print "the connection to the server was not successful<br/>";
print "<br/>";
@mysqli_connect_error();
}

DEFINE('DB_NAME','azulmediadb');
$dbc = @mysqli_select_db($lch,DB_NAME);
if($dbc == TRUE){
print "the connection to the database was successful<br/>";
print "<br/>";
}else
{
print "the connection to the database was not successful<br/>";
print "<br/>";
}

$q = "SELECT*FROM style";
$results = @mysqli_query($lch,$q);

if($results) {
$rows = @mysqli_num_rows($results);
print "There are $rows rows/records in the database<br/>";
print "<br/>";
}else{
print "there was an error with the execution of the SQL Query<br/>";
print "<br/>";
}

while($retrec = @mysqli_fetch_array($results,MYSQLI_ASSOC))
{
$id = $retrec['id'];
$color = $retrec['color'];
$url = $retrec['URL'];
}

?>

Το αποτέλεσμα που μου βγάζει τώρα είναι...

the connection to the server was successful

the connection to the database was successful

There are 3 rows/records in the database