Pages: 12Next
Current Page: 1 of 2
Unability to connect to MySQL DB's from work directory
Posted by: auttranadhie (---.Red-80-35-211.staticIP.rima-tde.net)
Date: October 04, 2008 08:56PM

Dear all,

As working under WWW directory I created another ones for my projects and then wrote my PHP files. As long as I know, this is correct for WAMP (under Windows XP Professional).

I try to connect to my databases using:

mysql_connect("localhost", "root", ""winking smiley

But I do not receive any response. Any solution? Should I change anything in the INI files or so?

The same files were tested on a MacPro (by using MAMP), and everything runs perfectly. I need to use any operating system; this is not a question of preferences.

Thanks in advance

--
Alberto Uttranadhie
auttranadhie@yahoo.com

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: October 04, 2008 09:02PM

wat colour is your wamp icon in the taskbar?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: auttranadhie (---.Red-80-35-211.staticIP.rima-tde.net)
Date: October 04, 2008 09:34PM

Hi, again,

First of all, thanks for soon response.

My WAMP icon is white (or any other it ought to be as active). In fact, on mouse over a popup appears reporting it is active. In any case, as running, is not in red.

Regards,

--
Alberto Uttranadhie
auttranadhie@yahoo.com

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: October 04, 2008 09:46PM

ok did u say u put ur file in the www folder


what is the entire code you are using?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: auttranadhie (---.Red-80-35-211.staticIP.rima-tde.net)
Date: October 04, 2008 10:07PM

Hi, again, Steven,

Here below you will find the entire code. This is just a test in order to know if I am able to connect to my database (what is called "ccea"winking smiley. The PHP files are under a directory called \www\ccea (where WWW is the WAMP working folder).

function connection()
{
if (!($cnn=mysql_connect("localhost","root",""winking smiley))
{
echo "Error on connecting database";
exit();
}
if (!mysql_select_db("ccea",$cnn))
{
echo "Error on selecting database";
exit();
}
return $cnn;
}

connection();

if ($cnn=true)
{
echo "You are connected";
}
else
{
echo "You are not connected";
}

Thanks again and regards,

--
Alberto Uttranadhie
auttranadhie@yahoo.com

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: October 04, 2008 10:14PM

try this code


<?php
$link = mysql_connect('localhost', 'root');
if (!$connect) { die('Could not connect: ' . mysql_error());}
echo 'Connected successfully';
mysql_close($connect);
?>

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: auttranadhie (---.Red-80-35-211.staticIP.rima-tde.net)
Date: October 04, 2008 10:20PM

Hi, Steven,

Such code worked but not my connection. It returns "Could not connect". I do not know if my problem maybe in any INI file or so.

Regards,

--
Alberto Uttranadhie
auttranadhie@yahoo.com

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: October 04, 2008 10:21PM

can your access phpmyadmin?

do u have a user root with no password?


goto h ttp://localhost/phpmyadmin/

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: auttranadhie (---.Red-80-35-211.staticIP.rima-tde.net)
Date: October 04, 2008 11:06PM

Hi,

Yes, I can access phpmyadmin. In fact, I have no need to enter any username or password.

Before using WAMP, I was trying with EasyWAMP and I had always to write username/password for accessing.

I have also checked my port 80, but everything works fine.

Regards,

--
Alberto Uttranadhie
auttranadhie@yahoo.com

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: klawncare1239 (---.quickconnectusa.com)
Date: October 05, 2008 01:45AM

Same problem here. I have a working database installed with a global user setup. Also have a root user with no password and global access permissions. Can view the database through phpmyadmin and have no errors through wamp.

However, trying to access this database through a php file proves useless. Tried your php code above, and had the same result "could not connect".

My WAMP icon is white. All services appear to be functioning properly. Can access webpages in the "www" directory. Just can't get my php files to access the database.

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: toivo (---.nsw.bigpond.net.au)
Date: October 05, 2008 06:43AM

auttranadhie Wrote:
-------------------------------------------------------
> Hi, again, Steven,
>
> Here below you will find the entire code. This is
> just a test in order to know if I am able to
> connect to my database (what is called "ccea"winking smiley.
> The PHP files are under a directory called
> \www\ccea (where WWW is the WAMP working folder).
>
> function connection()
> {
> if
> (!($cnn=mysql_connect("localhost","root",""winking smiley))
> {
> echo "Error on connecting database";
> exit();
> }
> if (!mysql_select_db("ccea",$cnn))
> {
> echo "Error on selecting database";
> exit();
> }
> return $cnn;
> }
>
> connection();
>
> if ($cnn=true)
> {
> echo "You are connected";
> }
> else
> {
> echo "You are not connected";
> }
>
> Thanks again and regards,


Hi Alberto,

There are a couple of problems with your code. Your function does not return the value of the variable $cnn. Because $cnn does not have a value in your test, the test should always fail. However, you may have a typo in the comparison 'if ($cnn=true)' because the expression inside the brackets is an assignment expression which gets the assigned value or true. You need to use == instead, or just use 'if ($cnn)'.

Regards,

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: toivo (---.nsw.bigpond.net.au)
Date: October 05, 2008 06:47AM

stevenmartin99 Wrote:
-------------------------------------------------------
> try this code
>
>
> <?php
> $link = mysql_connect('localhost', 'root');
> if (!$connect) { die('Could not connect: ' .
> mysql_error());}
> echo 'Connected successfully';
> mysql_close($connect);
> ?>


Hi Steven,

You mean 'if (!$link)' ;-)

Regards,
Toivo

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: October 05, 2008 08:04AM

oops yes....

it was 1 am sad smiley


both please ue this code



<?php
$connect = mysql_connect('localhost', 'root');
if (!$connect) { die('Could not connect: ' . mysql_error());}
echo 'Connected successfully';
mysql_close($connect);
?>

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: auttranadhie (---.Red-80-35-211.staticIP.rima-tde.net)
Date: October 05, 2008 07:16PM

Hi, again,

At last, and thank you all, I can access my databases. I tried last code and everything run pecfectly.

Could you recommend a good PHP editor? In Mac I am working with Smultron, not bad, but it is probably I will be working more time with Windows.

My best regards from Spain for all,

--
Alberto Uttranadhie
auttranadhie@yahoo.com

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: October 05, 2008 07:22PM

your welcome


notepad ++ is good editor

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: klawncare1239 (---.quickconnectusa.com)
Date: October 05, 2008 08:51PM

Ok,

Code above gives "connected successfully" message. So, that helps to see that I CAN connect to the database. However, I don't understand why my php script won't connect. It works fine on my server. I have created a database with the correct name and a user with the correct name and privileges. I've tried using the script with the user I created and also with "root" and no password. Either way, no go.

Here's a copy of the actual code of the file (where I've anonymized my cookie_host, database_username, database_user_password and database_name):

I've checked to make sure that the username, password and database name that I've used in this file match up with those that I created.

To reiterate, this file works fine on my server. I just wanted to have a test server where I could test new php pages without always having to upload them for testing. Below the code below I have also pasted what I see in the browser when I try to load index.php, which references cookiemonster.php (the file which contains the code below).


======================================================

define("MK__COOKIE_HOST", ".mydomain.com"winking smiley;
define("MK__COOKIE_URL", "ref"winking smiley;
define("MK__DATABASE_HOST", "localhost"winking smiley;
define("MK__DATABASE_USERNAME", "user_e1071"winking smiley;
define("MK__DATABASE_PASSWORD", "user-password"winking smiley;
define("MK__DATABASE_NAME", "user_e1071"winking smiley;
define("MK__DATABASE_TABLE", "form_23"winking smiley;


class Database
{

function Database()
{

$tmp_dblink = @mysql_pconnect(MK__DATABASE_HOST, MK__DATABASE_USERNAME, MK__DATABASE_PASSWORD);

if (!$tmp_dblink)
{

echo "<HTML>\n";
echo "<HEAD>\n";
echo "<TITLE>HomeBizHit.com - Database Connection Error</TITLE>\n";
echo "</HEAD>\n";
echo "<BODY><TABLE HEIGHT=\"50%\" WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD VALIGN=\"MIDDLE\" ALIGN=\"CENTER\">\n";
echo "<DIV ALIGN=\"CENTER\" STYLE=\"font-family: monospace; font-size: 11pt; color: maroon\"><B>[ HomeBizHit.com ]</B></DIV><BR>";
echo "<DIV ALIGN=\"CENTER\" STYLE=\"font-family: Tahoma, Arial; font-size: 9pt; color: black\"><B>Fatal Error</B>:&nbsp; Unable to open socket to database server.</DIV>\n";
echo "</TD></TR></TABLE></BODY>\n";
echo "</HTML>\n";
exit();

}

}

function Query($theQuery)
{

mysql_select_db(MK__DATABASE_NAME);
return(mysql_query($theQuery));

}

function NumRows($theResult)
{

return(mysql_num_rows($theResult));

}

function FetchArray($theResult)
{

return(mysql_fetch_array($theResult));

}

function FreeResult($theResult)
{

mysql_free_result($theResult);

}

}

$Database = new Database;


class Affiliate
{

var $AffiliateId;

function Affiliate()
{

global $Database;

if (isset($_GET[MK__COOKIE_URL]))
{

$result = $Database->Query("SELECT * FROM ".MK__DATABASE_TABLE." WHERE affiliate_id = '".$_GET[MK__COOKIE_URL]."';"winking smiley;
if (!$Database->NumRows($result))
{

$this->AffiliateId = $this->RandomGenerator();
$this->SetCookies($this->AffiliateId, TRUE);

} else
{

if (isset($_COOKIE["MKAFFILIATE"][1]))
{

if (isset($_COOKIE["MKAFFILIATE"][2]))
{

$this->AffiliateId = $_GET[MK__COOKIE_URL];
$this->SetCookies($this->AffiliateId, FALSE);

} else
{

if ($_COOKIE["MKAFFILIATE"][1] == $_GET[MK__COOKIE_URL])
{

$this->AffiliateId = $_GET[MK__COOKIE_URL];
$this->SetCookies($this->AffiliateId, FALSE);

} else
{

$this->AffiliateId = $_COOKIE["MKAFFILIATE"][1];
$this->SetCookies($this->AffiliateId, FALSE);

}

}

} else
{

$this->AffiliateId = $_GET[MK__COOKIE_URL];
$this->SetCookies($this->AffiliateId, FALSE);

}

}

} else
{

if (isset($_COOKIE["MKAFFILIATE"][1]))
{

$this->AffiliateId = $_COOKIE["MKAFFILIATE"][1];

if (isset($_COOKIE["MKAFFILIATE"][2]))
{

$this->SetCookies($this->AffiliateId, TRUE);

} else
{

$this->SetCookies($this->AffiliateId, FALSE);

}

} else
{

$this->AffiliateId = $this->RandomGenerator();
$this->SetCookies($this->AffiliateId, TRUE);

}

}

}

function RandomGenerator()
{

global $Database;
$tmpTotal = 0;

$result = $Database->Query("SELECT * FROM ".MK__DATABASE_TABLE." ORDER BY affiliate_id;"winking smiley;
while ($row = $Database->FetchArray($result))
{

for ($tmpCount = 1; $tmpCount <= $row["affiliate_weight"]; $tmpCount++)
{

$tmpArray[] = $row["affiliate_id"];
$tmpTotal++;

}

}
$Database->FreeResult($result);

shuffle($tmpArray);
$tmpAffiliate = rand(0, ($tmpTotal - 1));
return($tmpArray[$tmpAffiliate]);

}

function SetCookies($theAffiliate, $theRandomGenerator = FALSE)
{

setcookie("MKAFFILIATE[1]", $theAffiliate, time() + (60 * 60 * 24 * 363), "/", MK__COOKIE_HOST);

if ($theRandomGenerator == TRUE)
{

setcookie("MKAFFILIATE[2]", $theAffiliate, time() + (60 * 60 * 24 * 363), "/", MK__COOKIE_HOST);

} else
{

if (isset($_COOKIE["MKAFFILIATE"][2]))
{

setcookie("MKAFFILIATE[2]", $theAffiliate, time() - (60 * 60 * 24 * 363), "/", MK__COOKIE_HOST);

}

}

}

function Data($theField)
{

global $Database;

$result = $Database->Query("SELECT * FROM ".MK__DATABASE_TABLE." WHERE affiliate_id = '".$this->AffiliateId."';"winking smiley;
if (!$Database->NumRows($result))
{

return("Unknown Affiliate"winking smiley;

} else
{

while ($row = $Database->FetchArray($result))
{

$tmpValue = $row["affiliate_".strtolower($theField)];

}
$Database->FreeResult($result);

return($tmpValue);

}

}

}

$Affiliate = new Affiliate;


====================================================

This is what I see in the browser when I try to load my index.php file which has cookiemonster.php as an include

=====================================================

[ HomeBizHit.com ]

Fatal Error: Unable to open socket to database server.

======================================================



Edited 1 time(s). Last edit at 10/05/2008 09:14PM by klawncare1239.

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: klawncare1239 (---.quickconnectusa.com)
Date: October 06, 2008 11:19PM

Figured out my problem. No need for additional response.

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: AbdulMuqeet (116.71.29.---)
Date: October 09, 2008 09:42PM

Connection is done but

<?

$db=mysql_connect('localhost','root');
mysql_select_db("trad",$db);
$query= "SELECT * FROM techno WHERE hname LIKE '%".$name."%'";
$result=mysql_query($query);
while($record=mysql_fetch_row($result))
{
for($i=0;$i<count($record); $i++)
{
echo $record[$i]."<BR>";
}
echo "<BR>";
}

?>

my this code is not running and not giving any result just where i have entered data on mysql seprately and have seen it their.

"; } echo "
"; } ?>

In the output



Edited 1 time(s). Last edit at 10/09/2008 10:03PM by AbdulMuqeet.

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: toivo (---.nsw.bigpond.net.au)
Date: October 09, 2008 10:12PM

Hi,

Unless you have turned the option short_open_tag on in php.ini, you need to use the normal open tag:

<?php

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: Unability to connect to MySQL DB's from work directory
Posted by: AbdulMuqeet (116.71.29.---)
Date: October 09, 2008 10:15PM

yes i have changed it to <?php

but still the same problem

Options: ReplyQuote
Pages: 12Next
Current Page: 1 of 2


Sorry, only registered users may post in this forum.