Results 1 to 9 of 9

Thread: Apache, PHP, MySQL

  1. #1

    Apache, PHP, MySQL

    I just have a quick one... I am running a server with Apache, PHP, and MySQL. I can't get PHP to connect to MySQL though. I have a few test scripts from a "... for dummies" book, and the scripts that test for PHP alone work just fine. There are scripts to test that MySQL alone is working, and it is fine. However trying to get PHP to connect to MySQL hasn't worked yet. I can connect via command line just fine, but... I was wondering if I need to tell Apache or PHP where on my system the MySQL databases are or...? I have been racking my brains for about two weeks, configuring, reinstalling, etc. and have gotten nowhere. Any help would be great. Thanks.
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  2. #2

    Re:Apache, PHP, MySQL

    set up a php script that has
    <?php
    php_info();
    ?>
    in it and make sure all the mysql things are set up.
    It should be...
    whatdoyougetwhenyoumultiplysixbynine??

  3. #3

    Re:Apache, PHP, MySQL

    Yeah, I did this after the PHP installation, and it gave me all of the PHP info. I looked at the MySQL section, and it was enabled, and everything looks normal. Here is some of the script that I got from the 'for dummies' book, this script didn't work:

    <?php
    $user="ron";
    $host="localhost";
    $password="xxxxx";

    /* Section that executes query */
    if (@$form == "yes")
    {
    mysql_connect($host,$user,$password);
    mysql_select_db($database);
    $query = stripSlashes($query) ;
    $result = mysql_query($query);
    echo "Database Selected: <b>$database</b><br>
    Query: <b>$query</b>
    <h3>Results</h3>
    <hr>";
    if ($result == 0)
    echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");

    elseif (@mysql_num_rows($result) == 0)
    echo("<b>Query completed. No results returned.</b><br>");
    else
    {
    echo "<table border='1'>
    <thead>
    <tr>";
    for ($i = 0; $i < mysql_num_fields($result); $i++)
    {
    echo("<th>" . mysql_field_name($result,$i) . "</th>");
    }
    echo " </tr>
    </thead>
    <tbody>";
    for ($i = 0; $i < mysql_num_rows($result); $i++)
    {
    echo "<tr>";
    $row = mysql_fetch_row($result);
    for ($j = 0; $j < mysql_num_fields($result); $j++)
    {
    echo("<td>" . $row[$j] . "</td>");
    }
    echo "</tr>";
    }
    echo "</tbody>
    </table>";
    }
    echo "<hr><br>
    <form action=$PHP_SELF method=post>
    <input type=hidden name=query value=\"$query\">
    <input type=hidden name=database value=$database>
    <input type=submit name=\"queryButton\" value=\"New Query\">
    <input type=submit name=\"queryButton\" value=\"Edit Query\">
    </form>";
    unset($form);
    exit();
    }

    /* Section that requests user input of query */
    @$query = stripSlashes($query);
    if (@$queryButton != "Edit Query")
    {
    $database = " ";
    $query = " ";
    }
    ?>

    <form action=<?php echo $PHP_SELF ?>?form=yes method="post">
    <table>
    <tr>
    <td align="right"><b>Type in database name</b></td>
    <td>
    <input type=text name="database" value=<?php echo $database ?> >
    </td>
    </tr>
    <tr>
    <td align="right" valign="top"><b>Type in SQL query</b></td>
    <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" value="Submit Query"></td>
    </tr>
    </table>
    </form>

    This script does nothing. After I hit the submit button, the fields I filled in blank out, and the window status shows done. I am lost...
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  4. #4

    Re:Apache, PHP, MySQL

    you might want to try putting in some debugging.
    If you take alook at the commands, they usually return something depending on sucess or failure, so you can run
    $test = mysql_connect($host,$user,$password);;
    echo $test;
    to see if it worked.
    Try taking a look around some of the commands you have used and see if they have finished properly.
    Also take a look at the php website for some function reference, if you type in php.net/mysql_connect into the address bar it will automatically take you to the correct reference page

    Alastair
    whatdoyougetwhenyoumultiplysixbynine??

  5. #5

    Re:Apache, PHP, MySQL

    Okay, here is the code that I put in, just to make sure I incorporated it correctly:

    <?php
    $host="localhost";
    $user="ron";
    $password="XXXXXXX";

    mysql_connect($host,$user,$password);
    $test = mysql_connect($host,$user,$password);
    echo $test;
    ?>

    When I run it on the server, it printed "Resource id #2". Umm... what on earth?
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  6. #6

    Re:Apache, PHP, MySQL

    If you would like to try the script I got from the book, you can do this... Go to 24.10.6.236 and click on mysql-send.php. There are currently two databases, the default mysql, and one called "cams", so you should be able to use that db for a query. The only thing that is bugging me about this whole thing is that I am trying to learn PHP for a project, and it is impossible when even the examples in the book don't work. I mean, I have used a few test scripts (like the ones you will see if you go the site), and everything tells me that the components are working individually, but I have yet to get them to mesh...
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  7. #7

    Re:Apache, PHP, MySQL

    Well, that was completely dumb for me to put the address on this board... I can't remember a time when I have had so many hack attempts. Ridiculous. Funny this is, there is nothing to gain by getting into the server, that you can't already get. I really don't see a need to try to get into my /root or / directory unless the person are trying to be malicious. People these days...
    Asus A8V Deluxe Mobo
    AMD Athlon64 X2 4400 -939
    2GB Crucial DDR3200 Dual-Channel
    ATi AiW 9800 Pro 128DDR
    Audigy2 ZS
    Sony DRU-810 DVD+RW DL
    3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
    1 x Maxtor MaxLine SATA 120Gb 16Mb Cache

  8. #8

    Re:Apache, PHP, MySQL

    Quote Originally Posted by vwgtiturbo
    mysql_connect($host,$user,$password);
    $test = mysql_connect($host,$user,$password);
    echo $test;
    ?>

    When I run it on the server, it printed "Resource id #2". Umm... what on earth?
    Yeah, thats probally wriong..
    you could try
    @mysql_connect($host,$user,$password) or
    die "It failed";

    i think is the correct usage
    whatdoyougetwhenyoumultiplysixbynine??

  9. #9

    Re:Apache, PHP, MySQL

    it wasn't too long ago that this board was hacked itself... :-X makes you wonder..

Similar Threads

  1. Problem starting mysql conflicts with the RPM "mysql-5.0.27-1.fc6"
    By kamakshiganesh in forum Redhat / Fedora
    Replies: 2
    Last Post: 10-26-2007, 04:35 AM
  2. apache + MySQL + PHP
    By imported_root in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 09-24-2005, 07:49 AM
  3. Apache + SSL + PHP + MYSQL PET
    By gorn in forum Linux - General Topics
    Replies: 10
    Last Post: 12-24-2002, 05:57 AM
  4. php / mysql
    By kornp in forum Linux - Hardware, Networking & Security
    Replies: 5
    Last Post: 05-07-2002, 02:25 PM
  5. mysql
    By pinehead in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 04-02-2002, 08:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •