Solved

PHP Error

Posted on 2010-11-30
2
275 Views
Last Modified: 2012-05-10
I am not sure what is wrong with the code below, but when ever I attempt to execute it I get the following error:

PHP Warning:  mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in mysql.main.php on line 17

According to the PHP manual, I have mysql_fetch_assoc() written correctly. Not sure why this error is being thrown.
<?php



	// require the configurations file

	require(dirname(__FILE__) . "/configurations/config.inc.php");

	

	// open connection to mysql - source and destination

	$mysql_source_link_id = mysql_connect($argv[1], mysql_user, mysql_user_password);

	$mysql_destination_link_id = mysql_connect(destination_mysql_host, mysql_user, mysql_user_password);

	

	// open the databases for both - source and destination mysql instances

	$mysql_database_source = mysql_select_db($argv[2], $mysql_source_link_id);

	$mysql_database_destination = mysql_select_db(destination_database_name, $mysql_destination_link_id);

	

	// execute the select statement on the source

	$query_select = mysql_query($sql_select, $mysql_source_link_id); 

	

	for ($i=0; $i < ($row = mysql_fetch_assoc($query_select)); $i++) {

		

		echo $row["world_id"] . "\n";

		echo $row["room_id"] . "\n";

		echo $row["player_id"] . "\n";

		echo $row["timestamp"] . "\n";

		echo $row["is_blocked"] . "\n";

		echo $row["message"] . "\n";

		

	}

	

	mysql_free_result($query_select);

	

	// close connection to mysql - source and destination

	mysql_close($mysql_destination_link_id);

	mysql_close($mysql_source_link_id);



?>

Open in new window

0
Comment
Question by:plecostomus
2 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 34241768
I don't see '$sql_select' defined anywhere in that code.  Your 'mysql_query()' won't work without it.
0
 
LVL 1

Accepted Solution

by:
jebpotly earned 500 total points
ID: 34241771
http://us2.php.net/manual/en/function.mysql-query.php
"For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

"For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error."

I would guess that your "mysql_query($sql_select, $mysql_source_link_id); " statement on line 15 is returning a boolean which is why your warning is complaining about a boolean. What is the value of your $sql_select variable and what what do you get if you do a print_r($query_select)  on line 16 right after you do the query?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
uploading image to a profile page 7 36
Update from TABLE-A to TABLE-B 5 38
updating the date data 12 21
datetime in sql 6 25
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now