White_Lily Posted January 23, 2013 Share Posted January 23, 2013 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 https://forums.phpfreaks.com/topic/273514-mysqli_connect/ Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273514-mysqli_connect/#findComment-1407622 Share on other sites More sharing options...
White_Lily Posted January 23, 2013 Author Share Posted January 23, 2013 Notice: Undefined variable: connect in/home/sites/janedealsart.co.uk/public_html/social/inc/functions.php on line 17 Actually Jessica - yes it is producing an undefined variable error. Link to comment https://forums.phpfreaks.com/topic/273514-mysqli_connect/#findComment-1407654 Share on other sites More sharing options...
White_Lily Posted January 23, 2013 Author Share Posted January 23, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273514-mysqli_connect/#findComment-1407660 Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 Line 17... So there's a whole bunch of code you didn't post. Like I said - the code YOU ORIGINALLY POSTED could not produce that error. Link to comment https://forums.phpfreaks.com/topic/273514-mysqli_connect/#findComment-1407694 Share on other sites More sharing options...
White_Lily Posted January 23, 2013 Author Share Posted January 23, 2013 I figured it out, it was the $connect variable being undefined, how I don't know, but all I did was re-type the connection details re-uploaded the file, and the error disappeared and data from the database showed. Link to comment https://forums.phpfreaks.com/topic/273514-mysqli_connect/#findComment-1407722 Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 *smh* Whatever. Link to comment https://forums.phpfreaks.com/topic/273514-mysqli_connect/#findComment-1407727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.