p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

php_databases thread: Problem Selecting from MySQL


Message #1 by "Philip Heins" <fireantz@d...> on Mon, 13 Jan 2003 15:27:02
> 
> 	include("fcstring.php");
> 	mysql_connect($db_Host, $db_Username, $db_Pass) ||  
> die("<b><font 
> color=\"Red\" face=\"Arial\" size=\"2\">Error:</b></font><font 
> face=\"Arial\" size=\"2\"> Unable to connect to database: " . 
> mysql_error
> () . "</font>");

When you do a connect a resource id is returned. 
you should capture this like so..

	$db_handle = mysql_connect($db_Host, $db_Username, $db_Pass);

Then you select a database to work with like so..

	mysql_select_db("db_name",$db_handle);

Then when you issue your query you can do like so..

	$results = mysql_query($sqlquery,$db_handle);

Then to get results..

	$i=0;
	while ( $row = @mysql_fetch_object($results) )
	{
		print_r($row);
	}

I also reccomend that you read the following article..

	http://www.databasejournal.com/features/php/article.php/1485971

Cheers,
Justin.


> 

  Return to Index