Can not connect to MySQL

Discussion in 'Web Development & Web Hosting' started by tech291083, Sep 10, 2006.

  1. tech291083

    tech291083 Bit Poster

    47
    0
    14
    hi,

    i have been trying to make the following php script work on fedora 5 os. but it does not show any data from the database. can any one please help. the code has been taken without any change from an online tutorial here.

    http://www.freewebmasterhelp.com/tutorials/phpmysql/4

    so i think it should be ok and the database has also been designed just as mentioned in the tutorial.

    PHP:
    <?
    $username="username";
    $password="password";
    $database="your_database";

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM contacts";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();

    echo 
    "<b><center>Database Output</center></b><br><br>";

    $i=0;
    while (
    $i $num) {

    $first=mysql_result($result,$i,"first");
    $last=mysql_result($result,$i,"last");
    $phone=mysql_result($result,$i,"phone");
    $mobile=mysql_result($result,$i,"mobile");
    $fax=mysql_result($result,$i,"fax");
    $email=mysql_result($result,$i,"email");
    $web=mysql_result($result,$i,"web");

    echo 
    "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";

    $i++;
    }

    ?>
    i have checked mysql database and the data is there but i m getting confused here.help please. thanks
     
  2. jackd

    jackd Megabyte Poster

    555
    7
    64
    what error message are you getting (if one)
     
  3. tech291083

    tech291083 Bit Poster

    47
    0
    14
    basically nothing is displayed. there are no error messages at all. i m going nuts. now a new problem has started when i type 'su' and enter password at the shell prompt and then type 'konqueror' some strange messages are being displayed. which are as follows:


    Link points to "/tmp/ksocket-root"
    Link points to "/tmp/kde-root"
    kbuildsycoca running.........

    and so on. can not really understand what is going on. all was fine just a few mins ago. help me please.thanks.
     
  4. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    Error messages in this sort of situation can be a b**** to find.

    Best places to look are in 1) The Apache logs (assuming you are using Apache) and 2) the MySQL logs.

    Post those and we may get some clue.

    However - MySQL is really weird with permissions, and this may be your problem. Don't forget that Apache/PHP is a different user compared to when you are using the mysql command line, so make sure that the Apache user has been allowed.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  5. tech291083

    tech291083 Bit Poster

    47
    0
    14
    thanks guys,

    i did all you suggested but still getting no where so i m gonna do a reintall and let you know when done.thanks again.
     
  6. tech291083

    tech291083 Bit Poster

    47
    0
    14
    hi guys,

    just finished a new installation of fedroa 5 and so far i have the following situation;

    root account with a password set up during the installation

    user account with a password set up during the installation

    STEP 1 : MySQL/services started:

    i have started the httpd (apache) and mysqld (mysql) services as well. plus many more services which i do not even understand but this just to make sure that all is fine.


    STEP 2 : Setting up accounts to access MySQL:

    As mentioned earlier i have two users root and another users with a password for the fedora 5 os but not password or account for them to access mysql. could you give me a few command that i can use to set up 2 separate accounts and separate passwords for both root and the other user. i need mysql comand to do so. please provide me with some.

    STEP 3 : Privileges to be steup:

    now i have not yet touched mysql at all. what i want is a command which allows all the users all the privelges in terms of mysql ie insert,update,delete and all possible. and a command that allows all the users to access all the databases fully ie insert,update,delete and all possible.

    STEP 4 : Create a database/table in MySQL:

    after doing the privileges with the help of a command that you would give me, i will then create a database from the command line in mysql. i m not used to phpmyadmin as of now so bear with me please.

    STEP 5 : Connect PHP and MySQL:

    I will ask you for a simple php script if you can provide me with one. the previous one i still could not figure out much as it contained a loop of some sort. what i want a script to be able to do is just select all fields fro a table. like select * from tablename. as simple as possible.


    What I want:

    so please guys let me know if i m taking the above steps in the right order or not. also provide me with the commands as mentioned above steps 1-5 and a simple infact very simple php script as described above. thanks. waiting for your help.
     
  7. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    is the mysql_close() in the correct place, I take that to mean you are closing the connection to the database before anything can be displayed to the screen?
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  8. tech291083

    tech291083 Bit Poster

    47
    0
    14
    ya,

    i checked that many a time but still the problems stays where it was. so just did a completely new install of the fedora 5 and now waiting for some one to get me through the steps as mentioned above.thanks mate.
     
  9. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    Hmm, just wondering whether re-installing the OS would make any difference at all.
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  10. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    Ummm... Have you bothered going to the MySql site and reading their documentation? They have a ton of it that will explain how to work with just about any facet of a MySql database, and if you're planning on running a database you better have a thorough understanding of how MySql is set up. Depending on everyone else to hold your hand is a sure way to fail in the open source world. Pretty soon people will just tell you to rtfm.... I know I have that tendency when someone says they are just waiting for someone else to do the work for them....

    http://dev.mysql.com/doc/
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.