Results 1 to 8 of 8

Thread: Apache2 PHP Connect to DB clears rest of screen

  1. #1
    Join Date
    Feb 2014
    Beans
    3

    Apache2 PHP Connect to DB clears rest of screen

    Whenever I attempt to connect to a database (both sqlite3 and MySQL) in a php script, it does not connect and clears everything after it on the page.

    So the following works and this will print hello twice on the screen:
    <?php
    echo 'hello';
    ?>
    <h1> hello </h1>

    But as soon as I give any commands to connect to a database, It will not display anything after the command:
    <?php
    $con=mysqli_connect("example.com","user","pass","m y_db");
    echo 'hello';
    ?>
    <h1> hello </h1>

    It will not display hello on the screen afterwards, nor will it give any errors on the screen or in the logs.

    MySQL and SQLite are installed and working.

    Any Ideas? I am completely lost.

    Thanks!

  2. #2
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    827
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Apache2 PHP Connect to DB clears rest of screen

    I don't know if this is just a typo error in your post .. but I see a rogue space in your command

    $con=mysqli_connect("example.com","user","pass","m y_db");

    Your database would not be found.

  3. #3
    Join Date
    Feb 2014
    Location
    http://linuxac.org
    Beans
    10
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: Apache2 PHP Connect to DB clears rest of screen

    For display errors

    Try:
    Code:
    gksudo gedit /etc/php5/apache2/php.ini
    Or
    Code:
    sudo gedit /etc/php5/apache2/php.ini
    Find:
    Code:
    display_errors = Off
    Replace to
    Code:
    display_errors = On
    Restart Apache
    Code:
    sudo service apache2 restart
    Last edited by al3arbe1; February 21st, 2014 at 12:32 PM.

  4. #4
    Join Date
    Jan 2006
    Location
    Not heaven... Iowa
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Apache2 PHP Connect to DB clears rest of screen

    Recommendation is to use gksudo with gedit.
    Linux User #415691 Ubuntu User #8629
    Iowa Team (LoCo): [Wiki] [Launchpad] [Sub-forum]
    IRC channel: #ubuntu-us-ia on irc.freenode.net

  5. #5
    Join Date
    Feb 2014
    Location
    http://linuxac.org
    Beans
    10
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: Apache2 PHP Connect to DB clears rest of screen

    Hi lowan,
    Thanks
    gksudo not installed on ubuntu

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    8,096
    Distro
    Kubuntu Development Release

    Re: Apache2 PHP Connect to DB clears rest of screen

    Also, you should test that the connection was made successfully like this:
    Code:
    <?php
    $debug = 1;
    
    $con=mysqli_connect("example.com","user","pass","m y_db");
    if ($con && $debug) { 
        echo "Connected to database!";
    } else if ($debug) {
        echo "Could not connect to database!!!";
    }
    ?>
    The _connect functions return either a resource pointer or FALSE if no connection can be made. Setting debug to zero will turn off the announcements.
    Last edited by SeijiSensei; February 22nd, 2014 at 01:11 AM.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Feb 2014
    Beans
    3

    Re: Apache2 PHP Connect to DB clears rest of screen

    Sorry. Yeah, that's just a typo in the post. Thank you though!

  8. #8
    Join Date
    Feb 2014
    Beans
    3

    Re: Apache2 PHP Connect to DB clears rest of screen

    I removed then re-added apache2, php5 and mysql and it is magically working again. Everything displays as it should! Thank you a million for everyone's help!!

Tags for this Thread

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
  •