Am followoing this amazingly simple LAMP tutorial
http://ubuntuserverguide.com/2014/06/how-to-install-lamp-in-ubuntu-server-14-04-lts.html

  • Installing Apache
  • Installing MySQL
  • Installing PHP

The PROBLEM is:

  • When I check on my brower localhost/phpmysql.php
  • I just see BLANK PAGE
  • If the php had been runned i should see either CONGRATULATIONS or ERROR message back.
 <?php
    $con = mysql_connect("localhost","root","passwordxxxxxx");
    if (!$con)
    {
     die('Could not connect: ' . mysql_error());
    }
    else
    {
     echo "Congrats! connection established successfully";
    }
    mysql_close($con);
  ?>

Is there any error on this PHP code maybe? For example: if the password is wrong setup on the PHPMYSQL.PHP file I should get back and ERROR MESSAGE couse i have a ECHO.

Why am getting a blank response? any idea of some workaround? Thanks

  • Is the page failing to load, or is it 200 OK? You can check this by doing a Ctrl-Shift-C (on chromium) and clicking on the Network tab and then refreshing the page. Tell us what's under 'status' column for 'localhost/phpmysql.php' under Name? – SiddharthaRT Oct 24 '14 at 19:43
  • 500 Internal Server Error Thans for showing up, any idea where de problem comes from? – fuegofuego2 Oct 24 '14 at 19:50
  • Okay. So that means your server is not set up properly. Can you give us the lines that appear in /var/log/apache2/error.log? Just say in a terminal: less +F /var/log/apache2/error.log (if permission error, prefix sudo). Now in browser, refresh the page. Copy paste the new lines that came up in the terminal in something like pastebin and post the link here. – SiddharthaRT Oct 24 '14 at 19:57
  • Ok, Here is the error.log pastebin.com/jGNXbFgA – fuegofuego2 Oct 24 '14 at 20:23
  • You should now be able to figure out why the missing mysqli error is coming. If you can't, can you also pastebin your full phpmysql.php? – SiddharthaRT Oct 24 '14 at 20:38
up vote 0 down vote accepted

You could find a solution for your problem by searching here based on the error in the logs.

You were missing the php's Mysqli class. Installing MyPHPAdmin (PHPMyAdmin rather) installed mysqli as a side effect, i'm guessing.

  • I totally agree, really interesting methodology – fuegofuego2 Oct 24 '14 at 21:33

ok after I installed MyPHPAdmin it is working suddendly the PHP file, and i get back all the time: Connected successfully

So I appreciate you time and your ideas!

I know that you are looking to just connect and may just be getting started, but please stop using mysql_connect; I didn't even know it was still even supported at this point A quick reference point to start with PDO is http://php.net/manual/en/book.pdo.php

A quick example of what I use for my PDO connection

I have a file. We'll call it connection.php

<?php

    class DDB extends pdo{


    public $sitedb = '';
    public $siteconfig;
    public $sitesettings = array(
        'host'      => "localhost",
        'database'  => "yourdb",
        'username'  => "youruser",
        'password'  => "yourpass",
    );

    public function __construct(){

        $this->db = new PDO(
            "mysql:host={$this->sitesettings['host']};" .
            "dbname={$this->sitesettings['database']};" .
            "charset=utf8",
            "{$this->sitesettings['username']}",
            "{$this->sitesettings['password']}"
        );

        $this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    }

    }

Now you could also have a new class. Let's call it accounts.php So within accounts.php

<?php

    require_once("connection.php");

class Accounts() {
         public $db;
         public function __construct() {
               $this->db = new DDB();
         }

         public function GetAccountNames() {
                $query = <<<SQL
                SELECT username
                FROM accounts
SQL;
         $resource = $this->db->db->prepare( $query );
         $resource->execute();
         foreach($resource as $row) {
         echo $row['username'];
         }
     }

Now say you have users.php

<?php $accounts = new Accounts();
           $accounts->GetAccountNames();
       ?>

The user.php page would now loop through all the results of your accounts database. I know it's not much, but hopefully it's a good starting point to get you away from the deprecated function.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.