...

View Full Version : error



bunny1
03-24-2007, 03:32 AM
Any idea what it is

mysql_query(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)

i am calling a function in another page using include at the top of the page to get a connection to the database
Could this have anything to do with the problem


<?php

include("db.php");

function AddItem($itemId, $qty)
{

$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");

$row = mysql_fetch_row($result);
$numRows = $row[0];

if($numRows == 0)
{
mysql_query("insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)");
}
else
{
UpdateItem($itemId, $qty);
}
}


The page i am calling uses this code


<?php

$server="servername";
$user="user";
$pass="pass"; //these are set to the correct values
$database="db";

function ConnectToDb($server, $user, $pass, $database)
{
$s = mysql_connect($server, $user, $pass);
$d = mysql_select_db($database, $s);

if(!$s || !$d)
return false;
else
return true;
}


Thanks

Fumigator
03-24-2007, 03:38 AM
You've included the code for the function but you aren't calling the function anywhere. You just need to add


ConnectToDb($server, $user, $pass, $database);

after the include, or put that inside the include-- however you want to do it.

bunny1
03-24-2007, 03:47 AM
im really silly
thanks!

Nightfire
03-24-2007, 02:08 PM
Bunny, I've told you before. Use a subject title that describes what your problem is.

Armondo
03-24-2007, 06:57 PM
if you didn't give him an infraction...then i am going to get mad. i recieved a infraction once for "some minor css trouble"...and he has "error". that is like 2x worse >_>.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum