sruder

MySQL Inport Question

Recommended Posts

I know this question has been asked in lots of ways, lots of times... but need some help!

 

Looking to import from an MySQL database that uses data like this:

jan1.gif

 

Here is the database layout:

jan2.gif

 

When I enter the following code though - I get a error saying: "Could not connect: Can't connect to MySQL server on 'localhost' (10061)" - so even though I am not sure if the code is correct can't connect to the data base?

[/font][/size]

<?php
//We've included ../Includes/FusionCharts_Gen.php, which contains
//FusionCharts PHP Class to help us easily embed charts 
//We've also used ../Includes/DBConn.php to easily connect to a database.
include("FusionCharts_Gen.php");
include("DBConn.php");
//include 'dbc.php';
?>





<?php
//You need to include the following JS file, if you intend to embed the chart using JavaScript.
//Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
//When you make your own charts, make sure that the path to this JS file is correct. 
//Else, you would JavaScript errors.
?> 






<?php
//In this example, we show how to connect FusionCharts to a database.
//For the sake of ease, we've used an MySQL databases containing two
//tables.

// Connect to the Database
$link = connectToDB();

# Create pie 3d chart object using FusionCharts PHP Class
$FC = new FusionCharts("Pie3D","650","450"); 

# Set Relative Path of chart swf file.
$FC->setSwfPath(" ");

//Store chart attributes in a variable for ease of use
$strParam="caption=Factory Output report;subCaption=By Quantity;pieSliceDepth=30; showBorder=1;showNames=1;formatNumberScale=0;numberSuffix= Units;decimalPrecision=0";

# Set chart attributes
$FC->setChartParams($strParam);


// Fetch all factory records using SQL Query
// Store chart data values in 'total' column/field 
// and category names in 'FactoryName'
$strQuery = "select record_category, sum(record_amount) as total from record group by record_category";
echo $strQuery;
echo "
";
$result = mysql_query($strQuery) or die(mysql_error());

$i = 0;
while($test = mysql_fetch_array($result))
{ echo $test['record_category']." ".$test['total'];
echo "
";
$i++;
}
echo $i;
echo "
";
echo $row['total'];


//Pass the SQL Query result to the FusionCharts PHP Class function
//along with field/column names that are storing chart values and corresponding category names 
//to set chart data from database
if ($result) 
{
$FC->addDataFromDatabase($result, "total");
// $FC->addDataFromDatabase($result, "total", "record_category");
}

mysql_close($link);

# Render the chart
$FC->renderChart();

?>




 

 

Does anybody have any advice on making sure that it connects to the database first?

Edited by Guest

Share this post


Link to post
Share on other sites

Hi sruder,

 

Could you please check the MySQl host , MySQL username , MySQL password & MySQL database name that is given in DBConn.php is correct for your MySQL server

Edited by Guest

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now