The XAMPP CD example won't connect to mysql out of box

Problems with the Windows version of XAMPP, questions, comments, and anything related.

The XAMPP CD example won't connect to mysql out of box

Postby jbreon » 05. May 2015 23:42

Hi,

I installed XAMPP on Windows 7 and absolutely everything seems to work accept for being able to connect when I run the CD example.

I've played around with adding a user with pass and modifying the php mentioned to connect. It gets this no matter what I do. This didn't work immediately and I assume right after install it should without modification.

CD Collection (Example for PHP+MySQL+PDF Class)

A very simple CD programm.
CD list as PDF document.


Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp2\htdocs\xampp\cds.php on line 78
Could not connect to database!
Is MySQL running or did you change the password?


Any help would be appreciated.
Thanks,
Jack
User avatar
jbreon
 
Posts: 5
Joined: 05. May 2015 23:36
Operating System: Windows 7

Re: The XAMPP CD example won't connect to mysql out of box

Postby JJ_Tagy » 06. May 2015 00:32

Is MySQL running? Check the control panel.

Did you change the password for root? There are two areas in cds.php to add the password, if you did. Also the same two areas in cds-fpdf.php.
JJ_Tagy
 
Posts: 678
Joined: 30. January 2012 13:44
Operating System: Windows 10 Pro x64

Re: The XAMPP CD example won't connect to mysql out of box

Postby jbreon » 07. May 2015 17:00

Everything runs fine and all services running as expected. All examples except the CD using mySQL would work because it can't connect. I tried everything from creating users and specifically changing to connect to them and any suggestions I found that others had from my search. Most everyone's issue was resolved because they were doing something incorrectly. But, I don't see how it could be the case for me as I installed, ran all services, no issues. Then just tried out all examples with this one not working. I only made changes in an effort to try to figure out why with no idea. I tried disabling all virus/firewall which also had no effect.

oh, I know the mySQL is running fine for sure because I can access it just fine through mySQL PHP panel. So, it seems to me that if PHP and that can function I should be able to connect so I'm stumped.

I also verified ports and configs and find no obvious reason as to why it just don't see mySQL.
User avatar
jbreon
 
Posts: 5
Joined: 05. May 2015 23:36
Operating System: Windows 7

Re: The XAMPP CD example won't connect to mysql out of box

Postby Nobbie » 07. May 2015 18:47

Forget about that worthless cd demo program. As long phpmyadmin and your own scripts are running, dont waste your time with this very old not maintained demo program.
Nobbie
 
Posts: 8762
Joined: 09. March 2008 13:04

Re: The XAMPP CD example won't connect to mysql out of box

Postby jbreon » 07. May 2015 19:40

The problem is that no connection will work. I tried my own just in case.

I have to at some point get the energy I guess to understand why the mySQLPHP thing works. I really didn't think to look at where it is and how it connects.

Well I have console green and port correct on console. But I tried that "Status" choice and that indicates MySQL database is DEACTIVATED. Something connecting the two isn't right for some reason. I don't know enough about configuring the PHP to mySQL to know what it is that might be an issue. So, I guess I'll have to fumble around in it.

I don't understand how the phpMyAdmin connects as it doesn't look like flat php to do it.

Well I looked at status and it just does a connect using a setup user. So, I just can't do any connecting via php code.
User avatar
jbreon
 
Posts: 5
Joined: 05. May 2015 23:36
Operating System: Windows 7

Re: The XAMPP CD example won't connect to mysql out of box

Postby Altrea » 07. May 2015 20:57

Hi,

It is very difficult to help you with this amount of information. Please tell us exaclty:
  • how your users overciew in phpmyadmin looks right now
  • how you have done any users changes since xampp installation
  • how your cds.php is looking right know
  • what the response of a ping to localhost is

I would think that either your users are configured wrong or MySQL is taking a different user like any@localhost instead of root@any or your name resolution is doing something strange

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: The XAMPP CD example won't connect to mysql out of box

Postby jbreon » 10. May 2015 22:24

okay. I gave up on trying to connect using old mysql_connect and switched the code to use, from what I read the now preferred method, mysqli. Interestingly all worked perfectly as it should when I did so. I don't even want to spend more time figuring out why the other didn't work right after install. I did many installs, many changes, and system cleanups to ensure that it wasn't my environment and never figured out why the other doesn't work. So, I don't know but perhaps these files should be updated to use the sqli instead as in my case it was the only way it would work. I did the following changes and now the complete XAMPP install performs as expected.

Thanks to this little journey I'm convinced to just start using mysqli anyway!

Note my only changes are switching to sqli which was trivial. It included the CD demo and the status check that determines if the servers are active.

Changed C:\xampp\htdocs\xampp\cds.php to:
-------------------Start of cds.php----------------------------
<?php include("langsettings.php"); ?>

<?php
if (urlencode(@$_REQUEST['action']) == "getpdf") {
$mysqli = new mysqli("localhost", "root", "", "cdcol");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
die();
}

include ('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();

$pdf->SetFont('Helvetica', '', 14);
$pdf->Write(5, 'CD Collection');
$pdf->Ln();

$pdf->SetFontSize(10);
$pdf->Write(5, '© 2002/2003 Kai Seidler, oswald@apachefriends.org, GPL');
$pdf->Ln();

$pdf->Ln(5);


$pdf->SetFont('Helvetica', 'B', 10);
$pdf->Cell(40 ,7, $TEXT['cds-attrib1'], 1);
$pdf->Cell(100 ,7, $TEXT['cds-attrib2'], 1);
$pdf->Cell(20 ,7, $TEXT['cds-attrib3'], 1);
$pdf->Ln();

$pdf->SetFont('Helvetica', '', 10);

$result=mysqli_query($mysqli,"SELECT titel,interpret,jahr FROM cds ORDER BY interpret");

while ($row = mysqli_fetch_array($result)) {
$pdf->Cell(40, 7, $row['interpret'], 1);
$pdf->Cell(100, 7, $row['titel'], 1);
$pdf->Cell(20, 7, $row['jahr'], 1);
$pdf->Ln();
}

$pdf->Output();
exit;
}
?>

<html>
<head>
<title>apachefriends.org cd collection</title>
<link href="xampp.css" rel="stylesheet" type="text/css">
</head>

<body>

&nbsp;<p>
<h1><?php print $TEXT['cds-head']; ?></h1>

<?php print $TEXT['cds-text1']; ?><p>
<?php print $TEXT['cds-text2']; ?><p>

<?php

// Copyright (C) 2002/2003 Kai Seidler, oswald@apachefriends.org
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

$mysqli = new mysqli("localhost", "root", "", "cdcol");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
die();
}
?>

<h2><?php print $TEXT['cds-head1']; ?></h2>

<table border=0 cellpadding=0 cellspacing=0>
<tr bgcolor=#f87820>
<td><img src=img/blank.gif width=10 height=25></td>
<td class=tabhead><img src=img/blank.gif width=200 height=6><br><b><?php print $TEXT['cds-attrib1']; ?></b></td>
<td class=tabhead><img src=img/blank.gif width=200 height=6><br><b><?php print $TEXT['cds-attrib2']; ?></b></td>
<td class=tabhead><img src=img/blank.gif width=50 height=6><br><b><?php print $TEXT['cds-attrib3']; ?></b></td>
<td class=tabhead><img src=img/blank.gif width=50 height=6><br><b><?php print $TEXT['cds-attrib4']; ?></b></td>
<td><img src=img/blank.gif width=10 height=25></td>
</tr>


<?php
if(@$_REQUEST['interpret']!="")
{
$titel=mysqli_real_escape_string($mysqli,$_REQUEST['titel']);
$interpret=mysqli_real_escape_string($mysqli,$_REQUEST['interpret']);
$jahr=intval($_REQUEST['jahr']);
if($jahr=="")$jahr="NULL";
mysqli_query($mysqli,"INSERT INTO cds (titel,interpret,jahr) VALUES('$titel','$interpret',$jahr);");
}

if(@$_REQUEST['action']=="del")
{
mysqli_query($mysqli,"DELETE FROM cds WHERE id=".round($_REQUEST['id']));
}

$result=mysqli_query($mysqli,"SELECT id,titel,interpret,jahr FROM cds ORDER BY interpret;");

$i=0;
while( $row=mysqli_fetch_array($result) )
{
if($i>0)
{
echo "<tr valign=bottom>";
echo "<td bgcolor=#ffffff background='img/strichel.gif' colspan=6><img src=img/blank.gif width=1 height=1></td>";
echo "</tr>";
}
echo "<tr valign=center>";
echo "<td class=tabval><img src=img/blank.gif width=10 height=20></td>";
echo "<td class=tabval><b>".htmlspecialchars($row['interpret'])."</b></td>";
echo "<td class=tabval>".htmlspecialchars($row['titel'])."&nbsp;</td>";
echo "<td class=tabval>".htmlspecialchars($row['jahr'])."&nbsp;</td>";

echo "<td class=tabval><a onclick=\"return confirm('".$TEXT['cds-sure']."');\" href=cds.php?action=del&id=".$row['id']."><span class=red>[".$TEXT['cds-button1']."]</span></a></td>";
echo "<td class=tabval></td>";
echo "</tr>";
$i++;

}

echo "<tr valign=bottom>";
echo "<td bgcolor=#fb7922 colspan=6><img src=img/blank.gif width=1 height=8></td>";
echo "</tr>";


?>

</table>

<h2><?php print $TEXT['cds-head2']; ?></h2>

<form action=cds.php method=get>
<table border=0 cellpadding=0 cellspacing=0>
<tr><td><?php print $TEXT['cds-attrib1']; ?>:</td><td><input type=text size=30 name=interpret></td></tr>
<tr><td><?php print $TEXT['cds-attrib2']; ?>:</td><td> <input type=text size=30 name=titel></td></tr>
<tr><td><?php print $TEXT['cds-attrib3']; ?>:</td><td> <input type=text size=5 name=jahr></td></tr>
<tr><td></td><td><input type=submit border=0 value="<?php print $TEXT['cds-button2']; ?>"></td></tr>
</table>
</form>
<?php include("showcode.php"); ?>

</body>
</html>
-------------------End of cds.php----------------------------

Then I changed C:\xampp\htdocs\xampp\mysql.php to:

-------------------Start of mysql.php----------------------------
<?php
$mysqli = new mysqli("localhost", "pma", "");
if ($mysqli->connect_errno) {
echo "NOK";
} else {
echo "OK";
}
?>
-------------------End of mysql.php----------------------------
User avatar
jbreon
 
Posts: 5
Joined: 05. May 2015 23:36
Operating System: Windows 7

Re: The XAMPP CD example won't connect to mysql out of box

Postby Altrea » 10. May 2015 22:47

Okay, so the old mysql_ functions are working for everybody except you. That's okay :D
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: The XAMPP CD example won't connect to mysql out of box

Postby jbreon » 11. May 2015 13:12

Yes. It appears I am the only one in the world with this issue. Now when the second one comes they will actually continue to use it knowing how to go around it since you are not interested in being proactive. But hey, that's okay.
User avatar
jbreon
 
Posts: 5
Joined: 05. May 2015 23:36
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 23 guests