I have an error with some plaincart tutorial...🙁 it prints...

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\shopcart\library\database.php on line 4

config.php

<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);


session_start();


$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = 'root';
$dbName = 'plaincart';


$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);


define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR',  'images/product/');




define('MAX_CATEGORY_IMAGE_WIDTH', 75);


define('LIMIT_PRODUCT_WIDTH',     true);


define('MAX_PRODUCT_IMAGE_WIDTH', 300);


define('THUMBNAIL_WIDTH',         75);

if (!get_magic_quotes_gpc()) {
	if (isset($_POST)) {
		foreach ($_POST as $key => $value) {
			$_POST[$key] =  trim(addslashes($value));
		}
	}

if (isset($_GET)) {
	foreach ($_GET as $key => $value) {
		$_GET[$key] = trim(addslashes($value));
	}
}	
}


require_once 'database.php';
require_once 'common.php';

$shopConfig = getShopConfig();
?>

database.php

<?php
require_once 'config.php';

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

function dbQuery($sql)
{
	$result = mysql_query($sql) or die(mysql_error());

return $result;
}

function dbAffectedRows()
{
	global $dbConn;

return mysql_affected_rows($dbConn);
}

function dbFetchArray($result, $resultType = MYSQL_NUM) {
	return mysql_fetch_array($result, $resultType);
}

function dbFetchAssoc($result)
{
	return mysql_fetch_assoc($result);
}

function dbFetchRow($result) 
{
	return mysql_fetch_row($result);
}

function dbFreeResult($result)
{
	return mysql_free_result($result);
}

function dbNumRows($result)
{
	return mysql_num_rows($result);
}

function dbSelect($dbName)
{
	return mysql_select_db($dbName);
}

function dbInsertId()
{
	return mysql_insert_id();
}
?>

Im a newbie in php.

    you installed php, with out mysql

      Thank you for the help dagon.. I already install my sql. Is there any configuration with my sql during installation?

        The issue has nothing to do with installing the MySQL server but rather with the 'mysql' PHP extension. See the manual page [man]mysql.installation[/man] for more info, but you likely just need to uncomment the "extension=php_mysql.dll" line in your php.ini config file (assuming PHP was properly installed in the first place, of course).

        Also note that the 'mysql' library of functions is old and outdated; newer PHP projects should instead be using something like [man]MySQLi[/man], [man]PDO[/man], etc.

          Write a Reply...