0
votes

i want to move my sql database and i have exported and imported mysql.sql file from localhost to live server and now i m not getting the files and content from that database. what i do ? i did make sure connection to database if fine and successful

here's my page http://shooop23.byethost7.com

<?php

$db = mysqli_connect('','','','');
if(mysqli_connect_errno()){
    echo'Database Connection Failed with following errors: '. mysqli_connect_errno();
    die();
}


?>
2
Does the DB have the content? Does the PHP get the content?chris85
yes database have content and i have uploaded my files to my serverronaldo cr
So what happens when you query, result is just empty?chris85
Your sql connect seems empty .. you should declare the right connection paramScaisEdge
I guess they are intentionally omitted...xzoert

2 Answers

0
votes

Once you have successfully established a connection to MySQL, you need to perform a query specifying what you want to retrieve and then subsequently retrieve it.

The following example uses mysqli_fetch_row

You should explore the documentation to learn the basics.

$db = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');

if(mysqli_connect_errno()){
    echo'Database connection failed with the following error: '.mysqli_connect_errno();
    exit;
}

if ($result = mysqli_query($db, "SELECT MyCol1,MyCol2 FROM MyTable")) {
    while ($row = mysqli_fetch_row($result)) {
        echo"{$row[0]} - {$row[1]}<br>");
    }
    mysqli_free_result($result);
}

mysqli_close($db);
0
votes
$db = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
$sql="SELECT * FROM login";

here i connected and stored my database and set a sql command (which is now a string) into these two veriables.

if(mysqli_connect_errno()){
    echo'Database connection failed with the following error: '.mysqli_connect_errno();
exit;
}

this is to check if the database is correctly connected, if not then it will show some errors.

$result = mysqli_query($db,$sql);

here i put the database and the sql command to run my query.

while($row = mysqli_fetch_array($result)){
      echo $row['username'];
}

here finally outputting the usernames(username is one of the column in my table in this case) which matched with that query i will suggest This Sql site to get a better understanding on sql queries and try to improve the secuirty because this is the basic point where hackers try to inject their attact most offenly. Note : If your table's in the database are empty then it will not able to fetch anything