MySQL output is going somewhere else

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

MySQL output is going somewhere else

Postby CaribouDriver » 19. March 2011 00:23

I recently installed xampp on my laptop running Windows XP with Service Pack 3.

When I execute the file: C:\xampp\htdocs\GroundSettlements/index.php

by entering: http://localhost/GroundSettlements/ in my browser,

the output from php "echo" commands appear in the window, but the

corresponding MySQL output appears to be going elsewhere. In particular,

the code fragment:

Code: Select all
       $query="SELECT * FROM ground_unadjusted_gross";
       $result=mysqli_query($cxn,$query)
               or die ("failed to SELECT");
       if ($result) echo "<p>SELECT was successful</p>";


produces the line:
SELECT was successful


(I have independently determined that the table called ground_unadjusted_gross is non-empty)

question #1: Where is my MySQL output going ?
question #2: How can I redirect it to the browser window I'm working in ?
CaribouDriver
 
Posts: 3
Joined: 18. March 2011 23:52

Re: MySQL output is going somewhere else

Postby Altrea » 19. March 2011 13:33

Take a look at the php documentation for mysqli_query().
The examples on that page give you a complete process.

You should answer your questions on your own if you ask you the following questions:
- which php functions do i need (every function is designed for exactly one purpose)
- what return value does my php function(s) have
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: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: MySQL output is going somewhere else

Postby CaribouDriver » 25. March 2011 11:50

Thank you for your reply. I'm sorry my response has taken so long. I'm not only new to MySQL, but to this forum. It took me a while to find your response.

I don't know why I thought the SELECT query would display the data selected. Duh! Based on the documentation, SELECT queries return a "object" or "resource". If I want every SELECT query to be accompanied by a display, I need to write a "method" or "procedure" which incorpoares both the SELECT query and a means of displaying the result.

I do need to refer to the docummentation more often.
CaribouDriver
 
Posts: 3
Joined: 18. March 2011 23:52

Re: MySQL output is going somewhere else

Postby CaribouDriver » 30. March 2011 23:24

Since over a 100 people looked in on this thread, I thought I'd post my solution. It does the job, but I'm not happy with it yet. I generated two files: index.php and utilities.inc. Here's the code:
**************
index.php
*************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
require ("utilities.inc");
$server="localhost";
$username="CaribouDriver";
$username="root";
$password="****";
$new_link="newLink";
$cxn = new mysqli($server,$username,$password,$new_link);
if (mysqli_connect_error()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$table = "myTable";
$query="DESCRIBE $table";
spew($cxn,$query);
$query="SELECT * FROM $table";
spew($cxn,$query);
$cxn->close();
?>
</body>
</html>
*******************
utilities.inc
*******************
<?php
function spew($cxn,$query) {
$result= $cxn->query($query) or die ("$query failed");
$num = $result->num_rows;
$fields=mysqli_num_fields($result);
$i=0;
while($i<$num) {
$row=mysqli_fetch_array($result, MYSQLI_NUM);
$j=0;
while($j<$fields) {
printf("%s ", $row[$j]);
$j++;
}
printf("<br />");
$i++;
}
printf("<br />");
$result->close();
return;
}
?>
CaribouDriver
 
Posts: 3
Joined: 18. March 2011 23:52


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 54 guests