by 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>
<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'])." </td>";
echo "<td class=tabval>".htmlspecialchars($row['jahr'])." </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----------------------------