Jump to content
Larry Ullman's Book Forums

Mysql Connection Error


Recommended Posts

An error occurred in script 'C:\XAMPP\htdocs\effortless_e-commerce\index.php' on line 5:

require(effortless_e-commercemysql.inc.php) [function.require]: failed to open stream: No such file or directory

 

Array

 

(

 

[0] => Array

 

(

 

[file] => C:\XAMPP\htdocs\effortless_e-commerce\index.php

 

[line] => 5

 

[function] => my_error_handler

 

[args] => Array

 

(

 

[0] => 2

 

[1] => require(effortless_e-commercemysql.inc.php) [function.require]: failed to open stream: No such file or directory

 

[2] => C:\XAMPP\htdocs\effortless_e-commerce\index.php

 

[3] => 5

 

[4] => Array

 

(

 

[GLOBALS] => Array

 

*RECURSION*

 

[_POST] => Array

 

(

 

)

 

 

 

[_GET] => Array

 

(

 

)

 

 

 

[_COOKIE] => Array

 

(

 

[phpSESSID] => bqhon059t4qre5rf1trpcqjt96

 

)

 

 

 

[_FILES] => Array

 

(

 

)

 

 

 

[live] =>

 

[contact_email] => you@example

 

[_SESSION] => Array

 

(

 

)

 

 

 

)

 

 

 

)

 

 

 

)

 

 

 

[1] => Array

 

(

 

[file] => C:\XAMPP\htdocs\effortless_e-commerce\index.php

 

[line] => 5

 

[function] => require

 

)

 

 

 

)

 

 

 

Fatal error: require() [function.require]: Failed opening required 'effortless_e-commercemysql.inc.php' (include_path='.;C:\XAMPP\php\PEAR') in C:\XAMPP\htdocs\effortless_e-commerce\index.php on line 5

 

<?php

 

// This file contains the database access information.

// This file establishes a connection to MySQL and selects the database.

// This file defines a function for making data safe to use in queries.

// This file defines a function for hashing passwords.

// This script is begun in Chapter 3.

 

// Set the database access information as constants:

DEFINE ('DB_USER', 'ruby711');

DEFINE ('DB_PASSWORD', 'jaela711');

DEFINE ('DB_HOST', 'localhost');

DEFINE ('DB_NAME', 'ecommerce1');

 

// Make the connection:

$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

 

// Set the character set:

mysqli_set_charset($dbc, 'utf8');

 

// Function for escaping and trimming form data.

// Takes one argument: the data to be treated (string).

// Returns the treated data (string).

function escape_data ($data) {

 

global $dbc; // Database connection.

 

// Strip the slashes if Magic Quotes is on:

if (get_magic_quotes_gpc()) $data = stripslashes($data);

 

// Apply trim() and mysqli_real_escape_string():

return mysqli_real_escape_string ($dbc, trim ($data));

 

} // End of the escape_data() function.

 

// This next block is added in Chapter 4.

 

// This function returns the hashed version of a password.

// It takes the user's password as its one argument.

// It returns a binary version of the password, already escaped to use in a query.

function get_password_hash($password) {

 

// Need the database connection:

global $dbc;

 

// Return the escaped password:

return mysqli_real_escape_string ($dbc, hash_hmac('sha256', $password, 'c#haRl891', true));

 

} // End of get_password_hash() function.

 

// Omit the closing PHP tag to avoid 'headers already sent' errors!

?>

Link to comment
Share on other sites

An error occurred in script 'C:\XAMPP\htdocs\effortless_e-commerce\index.php' on line 5:

require(effortless_e-commercemysql.inc.php) [function.require]: failed to open stream: No such file or directory

 

You are not including this file with the warning. Look at the path and make sure it's right.

Link to comment
Share on other sites

You are not including this file with the warning. Look at the path and make sure it's right.

 

********config.php*********

<?php
$live = false;
$contact_email = 'you@example';

define('BASE_URI', 'http://localhost/effortless_e-commerce/');
// define('BASE_URI', 'includes/pdf');
define('BASE_URL', 'www.example.com/');
define('MYSQL', BASE_URI . 'mysql.inc.php');

session_start();


// Begin defining an error-handling function:
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) {
global $live, $contact_email;

// Begin creating a detailed error message:
$message = "An error occurred in script '$e_file' on line $e_line:\n$e_message\n";

// Add the backtrace information:
$message .= "<pre>" .print_r(debug_backtrace(), 1). "</pre>\n";

// Or just append $e_vars to the message:
//	$message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n";

if(!$live) {
echo '<div class="error">' .nl2br($message). '</div>';

// If the site is live, send the error in an email:
} else {
error_log($message, 1, $contact_email, 'From:admin@example.com');

if($e_number != E_NOTICE) {
	echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div>';
}

} // End of $live If-ELSE.
	return true;

	} // End of my_error_handler() definition.

	//*****************************************

	/* This line actually tells php to use the customer function for handling errors.
	   If you don't execute this function call, then PHP will still use its default handler.
	   This is also why a parse error won't go through your own error handler, because the parse
	   error prevents the PHP script from being exectued.
	*/

	set_error_handler('my_error_handler');
?>



 

**********index.php************

<?php

require('./includes/config.inc.php');

require(MYSQL);

include('./includes/header.html');

// page-specific content:
?><h3>Welecome</h3>
<p>Welecome to Knowledge is Power, a site dedicated to keeping you up to date on the Web security and programming information you need to know. Blah, blah, blah, Yadda, yadda, yadda.</p>

<?php
include('./includes/footer.html');
?>

 

*******mysql.inc.php******

<?php

// This file contains the database access information. 
// This file establishes a connection to MySQL and selects the database.
// This file defines a function for making data safe to use in queries.
// This file defines a function for hashing passwords.
// This script is begun in Chapter 3.

// Set the database access information as constants:
DEFINE ('DB_USER', 'ruby711');
DEFINE ('DB_PASSWORD', 'jaela711');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'ecommerce1');

// Make the connection:
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Set the character set:
mysqli_set_charset($dbc, 'utf8');

// Function for escaping and trimming form data.
// Takes one argument: the data to be treated (string).
// Returns the treated data (string).
function escape_data ($data) { 

global $dbc; // Database connection.

// Strip the slashes if Magic Quotes is on:
if (get_magic_quotes_gpc()) $data = stripslashes($data);

// Apply trim() and mysqli_real_escape_string():
return mysqli_real_escape_string ($dbc, trim ($data));

} // End of the escape_data() function.

// This next block is added in Chapter 4.

// This function returns the hashed version of a password.
// It takes the user's password as its one argument.
// It returns a binary version of the password, already escaped to use in a query.
function get_password_hash($password) {

// Need the database connection:
global $dbc;

// Return the escaped password:
return mysqli_real_escape_string ($dbc, hash_hmac('sha256', $password, 'c#haRl891', true));

} // End of get_password_hash() function.

// Omit the closing PHP tag to avoid 'headers already sent' errors!
?>

 

My index.php is in the root dir and my includes is the root dir along supporting files.

Link to comment
Share on other sites

 Share

×
×
  • Create New...