burntheblobs Posted October 28, 2008 Share Posted October 28, 2008 For some reason, this function will not return $cxn. Here a simple function that I am using to connect to my database. If I just stick the code right in my program it works, however if I try to call it as a function, it does not. Even when I put the information directly into the $cxn variable, it does not work. function dbconnect() { $user="MYUSERNAME"; $host="localhost"; $password="MYPASSWORD"; $database="MYDATABASE"; $cxn = mysqli_connect($host,$user,$password,$database) or die ("Couldn't Connect to server."); return $cxn; } Link to comment https://forums.phpfreaks.com/topic/130387-solved-function-wont-return-variables/ Share on other sites More sharing options...
ratcateme Posted October 28, 2008 Share Posted October 28, 2008 how are you calling the script? like dbconnect(); //or $cxn = dbconnect(); if you are using the first method adding global $cxn; before $user=... should do what you want. Scott. Link to comment https://forums.phpfreaks.com/topic/130387-solved-function-wont-return-variables/#findComment-676343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.