Jump to content

mysqli_connect - what am I doing wrong


Recommended Posts

Can someone please, please, please tell me wtf is going here before I go totally postal and shoot up my ISP.  If I insert this code at the top of any of my web pages it  halts the page and nothing below it gets processed. I just get a blank page.  Even if I try to make an error on purpose, nothing, just a blank page. All this works perfectly on PHP 5.4 and under. Currently using 5.6 which I downgraded from 7.2 thinking maybe that was an issue. Running on Linux Mint 19. I thought this might be a good hobby since I had a spare laptop just lying around, but maybe I was mistaken - too much time already wasted today on this. Not like the old Slackware days.

I have tried the "serverhost" etc without quotes as well. I can't post all what I have done today, but I must have been on a 100 websites and tried 100 different iterations of the below code.

Thanks

<?php

define("serverhost", "localhost");    
define("serveruser", "test");
define("serverpass", "pass");
$db = "mydb";

$connect = mysqli_connect("serverhost", "serveruser", "serverpass", $db);

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}

?>

Link to post
Share on other sites

Take the quotes off the constant connection parameters in the connect string. It is also standard practice to use all UPPERCASE for constants.

$connect = mysqli_connect(serverhost, serveruser, serverpass, $db);

 

Edited by benanamen
Link to post
Share on other sites
21 hours ago, benanamen said:

Take the quotes off the constant connection parameters in the connect string. It is also standard practice to use all UPPERCASE for constants.


$connect = mysqli_connect(serverhost, serveruser, serverpass, $db);

From my original post...... I have tried the "serverhost" etc without quotes as well.

I have just tried the exact same code on Windows 10 running apache/mysql/php7.2 and it works like a charm, so I am thinking maybe there is something wrong with PHP or MySQL on the Linux machine.  Possibly in php.ini or my.cnf. As before, wherever the code is inserted to connect to the mysql server, the script halts and nothing after it is displayed.

Anyone??

Thanks

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.