Page 1 of 1

PHP query via Datasource name

Posted: Mon Jan 23, 2006 12:05 pm
by webacadie
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi I'm trying to make a query in PHP that will let me retrieve information from my Microsoft Acces database via a datasource name. I do not get any error message but it show me a blank page.

I don't know How to display my query result. I a Cold fusion expert but don't know nothing about PHP,

Code: Select all

<?
include('adodb.inc.php');       # charge le code deADOdb
$conn = &ADONewConnection('access');    # crée une connexion
$conn->PConnect('dsdatabase');   # se connecte à MS-Access, northwind DSN
$recordSet = &$conn->Execute('select id, name, client from client');

if (!$recordSet) 
	print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {

	print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
	$recordSet->MoveNext();
}

$recordSet->Close(); # optionnel
$conn->Close(); # optionnel
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Jan 24, 2006 10:19 am
by webacadie
Nobody knows how to do this or what?

Re: PHP query via Datasource name

Posted: Tue Jan 24, 2006 10:21 am
by Charles256
webacadie wrote:Hi I'm trying to make a query in PHP that will let me retrieve information from my Microsoft Acces database via a datasource name. I do not get any error message but it show me a blank page.

I don't know How to display my query result. I a Cold fusion expert but don't know nothing about PHP,

Code: Select all

<?
include('adodb.inc.php');       # charge le code deADOdb
$conn = &ADONewConnection('access');    # crée une connexion
$conn->PConnect('dsdatabase');   # se connecte à MS-Access, northwind DSN
$recordSet = &$conn->Execute('select id, name, client from client');

if (!$recordSet) 
	print $conn->ErrorMsg();
else
{
while (!$recordSet->EOF) {

	print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
	$recordSet->MoveNext();
}
}

$recordSet->Close(); # optionnel
$conn->Close(); # optionnel
?>
added {} to the else....that could be it..not sure....look up set_ini in the php manual and set error reporting to all along with display errors to on

Posted: Tue Jan 24, 2006 11:20 am
by webacadie
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Finally it work with this code

Code: Select all

<?php

$db = 'C:\\domains\\domains.com\\db\\mydb.mdb';

$conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');

$conn->open('dsname'); 

$sql = 'SELECT   id, nom, client
	FROM     client
	where id = 5';
$rs = $conn->Execute($sql);

?>

<table>
<tr>
	<th>Product Name</th>
	<th>Quantity Per Unit</th>
	<th>Unit Price</th>
</tr>
<?php while (!$rs->EOF) { ?>
	<tr>
		<td><?php echo $rs->Fields['id']->Value ?></td>
		<td><?php echo $rs->Fields['nom']->Value ?></td>
		<td><?php echo $rs->Fields['client']->Value ?></td>
	</tr>
	<?php $rs->MoveNext() ?>
<?php } ?>
</table>

<?php

$rs->Close();
$conn->Close();

$rs = null;
$conn = null;

?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]