Xtremer360 Posted May 18, 2011 Share Posted May 18, 2011 I'm trying to find out what is wrong here. Its not echoing the error. if (!$dbc) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } Link to comment https://forums.phpfreaks.com/topic/236771-db-error/ Share on other sites More sharing options...
Xtremer360 Posted May 18, 2011 Author Share Posted May 18, 2011 My database connection works because I use the file for my custom CMS script however the only way it'll let me use that connection is if I put a require code inside of each of my functions on my functions page. I'm not sure why that's needed. When I take out the require dbconfig file out of each function it says that the mysqli_query is returning NULL for all of my functions. I'm not sure why I have to have the file included. <?php /** * @author Jeff Davidson * @copyright 2010 */ // This file contains the database access information and establishes a connection to MySQL and selects the database // Set the database access information as contstants DEFINE ('DB_USER', '?'); DEFINE ('DB_PASSWORD', '?'); DEFINE ('DB_HOST', '?'); DEFINE ('DB_NAME', '?'); // Make the database connection $dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if ($dbc) { }else { die('Connect Error: ' . mysqli_connect_error()); } ?> This is just the header.php of my webpage. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Kansas Outlaw Wrestling :: True Outlaws of the Midwest</title> <link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/css/styles.css" /> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript" src="http://www.kansasoutlawwrestling.com/js/kow.js"></script> <?php require ("efedmanager/inc/dbconfig.php") ?> <?php require ("functions.php"); ?> </head> Link to comment https://forums.phpfreaks.com/topic/236771-db-error/#findComment-1217163 Share on other sites More sharing options...
Pikachu2000 Posted May 18, 2011 Share Posted May 18, 2011 Variable scope. Pass $dbc to the functions as an argument, after establishing the connection. Link to comment https://forums.phpfreaks.com/topic/236771-db-error/#findComment-1217178 Share on other sites More sharing options...
Xtremer360 Posted May 18, 2011 Author Share Posted May 18, 2011 so inside of my functions file I'm going to do this: function rosterlist($styleID, $dbc) { What did you mean by the second part? Link to comment https://forums.phpfreaks.com/topic/236771-db-error/#findComment-1217184 Share on other sites More sharing options...
Pikachu2000 Posted May 18, 2011 Share Posted May 18, 2011 Just make sure $dbc = mysqli_connect( etc., is defined before you try to pass it to a function to use with a query. Link to comment https://forums.phpfreaks.com/topic/236771-db-error/#findComment-1217190 Share on other sites More sharing options...
Xtremer360 Posted May 18, 2011 Author Share Posted May 18, 2011 Thank you sir. Link to comment https://forums.phpfreaks.com/topic/236771-db-error/#findComment-1217193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.