Jump to content

mysqli_connect()


White_Lily

Recommended Posts

Hi, I have ahd a slight problem with the deprecation of mysql_*() functions, and so are swapping them for mysqli_*() functions, how I have come across an error which states that $connect is undefined.

 

<?php

$GLOBALS["host"] = "localhost";
$GLOBALS["user"] = "web113-social-1";
$GLOBALS["pass"] = "********";
$GLOBALS["database"] = "***************";

$connect = mysqli_connect($GLOBALS["host"], $GLOBALS["user"], $GLOBALS["pass"], $GLOBALS["database"]);
?>

 

I have compared this against php.net's examples, and this code looks almost exact. I dont know what the problem is. Any help would be appreciated.

 

- Lily

Link to comment
Share on other sites

Why are you putting sensitive information into the globals array? Use constants.

 

The code you've posted would not produce an error about an undefined variable. You're also not checking for errors.

Edited by Jessica
Link to comment
Share on other sites

Okay, so I looked back at php.net to see what error checking they use...

 

<?php

$connect = mysqli_connect("localhost", "username", "password", "database");

if(!$connect){
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
}

echo 'Success... ' . mysqli_get_host_info($connect) . "\n";
?>

 

Guess what... Still getting an Undefined $connect error... dispite manually typing in the connection settings.

Edited by White_Lily
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.