Php and My Sql and Connections to DB

Discussion in 'PHP' started by kolucoms6, Aug 27, 2014.

  1. #1
    Basic primary level question :

    [​IMG]

    Above is the structure of my Mysql.

    When I am running :

    <?php
    
    // Deprecated as of PHP 5.4.0
    $link = mysql_connect('localhost', "easydial_ameyaa","xxxxxxxx");
    $db_list = mysql_list_dbs($link);
    
    while ($row = mysql_fetch_object($db_list)) {
         echo $row->Database . "\n";
    }
    ?>
    Code (markup):
    I returns me
    information_schema

    I want to access records form candidate_list. How to do that ?

    I tried below code but Its returns me Blank :

    <CODE>
    <?php
    //connect database
    $con=mysql_connect("localhost","easydial_ameyaa","xxxxxx") or die(mysql_error());

    // select database
    mysql_select_db("easydial_ameyaa",$con) or die(mysql_error());;

    $data="SELECT * FROM Candidate_List";
    $val=mysql_query($data);
    while($row=mysql_fetch_object($val)) or die(mysql_error());
    {
    echo $row->EmailID." ".$row->Salary." ".$row->JobType." ".$row->Mobile."<br/>";
    }
    mysql_close($con);
    ?>
    </CODE>
     
    kolucoms6, Aug 27, 2014 IP
  2. abhicyco

    abhicyco Active Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #2
    there might be some problem with the query.

    Try ini_set("display_errors",1); in the beginning of the code to display all errors and then you can debug easily
     
    abhicyco, Aug 27, 2014 IP
  3. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #3
    Tried but No Error .. Any Issues with my code ? Why its not shwoing candidate_list as table or easydial_ameyaa as db ?
     
    kolucoms6, Aug 27, 2014 IP
  4. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #4
    <?php
    //connect database
    $con=mysql_connect("localhost","easydial_ameyaa","xxxxxx") or die(mysql_error());
    
    // select database
    mysql_select_db("easydial_ameyaa",$con) or die(mysql_error());;
    
    $data="SELECT * FROM Candidate_List";
    $val=mysql_query($data);
    while($row=mysql_fetch_object($val)) or die(mysql_error());
    {
    echo $row->EmailID." ".$row->Salary." ".$row->JobType." ".$row->Mobile."<br/>";
    }
    mysql_close($con);
    ?>
    Code (markup):
    I tried above code..
     
    kolucoms6, Aug 27, 2014 IP
  5. donjajo

    donjajo Active Member

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    51
    #5
    Try switching over to MySQLi or PDO then we see where you've got your problem :)
     
    donjajo, Aug 29, 2014 IP
  6. funzie

    funzie Well-Known Member

    Messages:
    71
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    123
    #6
    Make sure that the user you are connecting as has access to the database you want. You say it's connecting to the information_schema, that is a default MySQL database. Also try to select the database you want in your select.

    Try:
    $data="SELECT * FROM easydial_ameyaa.Candidate_List";
    Code (markup):
     
    funzie, Sep 1, 2014 IP
  7. Ratty

    Ratty Active Member

    Messages:
    565
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    95
    Digital Goods:
    1
    #7
    Ratty, Sep 2, 2014 IP
  8. pmf123

    pmf123 Notable Member

    Messages:
    1,449
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    215
    #8
    you have to do a query before you can get results
     
    pmf123, Sep 15, 2014 IP