DataRater Posted August 14, 2008 Share Posted August 14, 2008 I'm trying to make a connection like this and the code is inside a class require_once('database.php') $YSLink=DBConnection('database'); if(!is_resource($YSLink)) { echo "Failed to connect to the server"; } and it tells me it failed database.php looks like this and is not a class function DBConnection($database_p) { $Space = " "; //-------- Set up Variables ----------------------------------- $HostName = 'xxxxx'; $DatabaseName = $database_p; $UserName = 'yyyyyyy'; $Password = 'zzzzz'; $MySQLLink = @mysqli_connect( $HostName, $UserName, $Password,$DatabaseName ); if( !$MySQLLink ) { Trace(false,"DBConnection: Can't connect to MySQL: ".mysql_error()); exit(); } else { Trace(false,"DBConnection: Connection to database made - Whoopee!!!!!!<br />"); } return($MySQLLink); }//DBConnection() and this tells me I've made the connection Whoopee!!!!!! Why didn't the connection get copied over? Link to comment https://forums.phpfreaks.com/topic/119666-solved-im-losing-the-mysql-connection-link/ Share on other sites More sharing options...
DataRater Posted August 14, 2008 Author Share Posted August 14, 2008 I've done some investigating and this looks interesting. There is a contradiction. Any idea why? function DBConnection($database_p) { $Space = " "; //-------- Set up Variables ----------------------------------- $HostName = 'xxxxx'; $DatabaseName = $database_p; $UserName = 'yyyyyyy'; $Password = 'zzzzz'; $MySQLLink = @mysqli_connect( $HostName, $UserName, $Password,$DatabaseName ); if(!is_resource($MySQLLink)) { echo "DBConnection()out: Bad Connection";This gets returned } else{ echo "DBConnection()out: Good Connection<br />"; } if( !$MySQLLink ) { Trace(false,"DBConnection: Can't connect to MySQL: ".mysql_error()); exit(); } else { Trace(false,"DBConnection: Connection to database made - Whoopee!!!!!! This gets returned "); } return($MySQLLink); }//DBConnection() Link to comment https://forums.phpfreaks.com/topic/119666-solved-im-losing-the-mysql-connection-link/#findComment-616552 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 remove the @ from in front of mysqli and ensure error_reporting is set to E_ALL and display_errors is turn on Link to comment https://forums.phpfreaks.com/topic/119666-solved-im-losing-the-mysql-connection-link/#findComment-616557 Share on other sites More sharing options...
DataRater Posted August 14, 2008 Author Share Posted August 14, 2008 I've solved it. As with most nasty problems there was a few things not quite right. is_resource doesn't seem to work with the i function. so mysqli_connect wasn't good. I was using mysql_real_escape_string instead of the i function mysqli_real_escape_string so had my parameters round the wrong way. So solved now. Link to comment https://forums.phpfreaks.com/topic/119666-solved-im-losing-the-mysql-connection-link/#findComment-616604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.