Question

Mysqli_connect create error 500

Hey! I get HTTP error 500 everytime I try to use mysqli_connect in my php file.

This is my code and link to the file I am having trouble with: http://138.68.86.134/getInfo.php

<?php
  session_start();

  if(!isset($_SESSION["access"])) {
    echo "null";
  } else if (isset($_SESSION["access"])) {
   // Here I am trying to use mysqli_connect
    $db = mysqli_connect("138.68.86.134", "root", "mypassword", "database")
    echo "Confirmed";
  } else {
    echo "Something went wrong...";
  }

 ?>

This is my Info.php file: http://138.68.86.134/info.php

I’ve followed every step for Debain LAMP tutorial here on DigitalOcean still this doesn’t work. I am very frustrated and I would highly appreciate any answer! Much love <3


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

@southsweden

Try this quick solution and if it works I will explain it to you.

Replace 138.68.86.134 with 127.0.0.1 and try again.

@southsweden

Before we get to troubleshooting, I would highly recommend and encourage you to use a created user instead of root. Should someone find a way in to your application, root access grants them the ability to remove everything (including other databases). You should never run as root :-).

That said, you’re missing a ; at the end of the function call for mysqli_connect().

i.e. This line:

$db = mysqli_connect("138.68.86.134", "root", "mypassword", "database")

Should be:

$db = mysqli_connect("138.68.86.134", "root", "mypassword", "database");

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.