-3

I have been trying for the past couple days to establish a connection to a MySQL db. I keep getting this error : PHP Parse error: syntax error, unexpected 'mysqli_connect' (T_STRING). This is all of the code in the script currently. I can't find the reason for the error.

$host = "localhost";
$user = "username";
$pass = "pass";
$db = "database";

$c =  mysqli_connect($host, $user, $pass, $db);

So, the issue was with an invisible Unicode character. I had copy pasted some of the code from another site. Resolved by re-entering manually. Thanks to the person who mentioned this, it looks like their answer was removed. I would have never figured this out. Thanks

swatinvicor
  • 11
  • 1
  • 2
  • 2
    i dont see how you can get that error, from this code, are you sure its the right code? –  Oct 10 '17 at 21:53
  • I would bet one of those variable stings actually has a character that needs escaping –  Oct 10 '17 at 21:59

2 Answers2

-3

Below should help :)

$mysqli = new mysqli($host, $user, $pass, $db);
$connection = ($GLOBALS["___mysqli_ston"] = mysqli_connect($host,  $user,  $pass));
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $db)) or die('offline');
-4

Parse error: syntax error, unexpected T_STRING

usually means you have a bad string somewhere on that line.

oz123
  • 27,559
  • 27
  • 125
  • 187
AbhiG
  • 1
  • 2