Hello, I am having great trouble adapting to code with an ODBC database!
Can someone help me by showing me how to make a query from an ODBC database and then assigning the results into variables.
E.G
$sql=Select ID, NAME, LAST_NAME FROM DATABASE WHERE id=$id;
Then put the values (ID, NAME and LAST_NAME) obtained from the database into variables $ID, $NAME, $LAST_NAME
Another question:
I’ve got 3 variables ($ID1, $ID2, $ID3) containing (152,168,335, respectively)
What would the php command be to make a variable = 152-168-335 and not 655 (=152+168+355)
Cheers guys!
using variables with odbc database
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: using variables with odbc database
I snagged this code from your drop-down menu post and modified it slightly...FE wrote:Can someone help me by showing me how to make a query from an ODBC database and then assigning the results into variables.
E.G
$sql=Select ID, NAME, LAST_NAME FROM DATABASE WHERE id=$id;
Then put the values (ID, NAME and LAST_NAME) obtained from the database into variables $ID, $NAME, $LAST_NAME
Code: Select all
<?php
if (!$connectionstring = odbc_connect("dbname","username","********"))
{
die('Could not connect to my database...');
}
$id = 1; // This would actually be set programmatically I presume?
$query = "SELECT ID, NAME, LAST_NAME FROM DATABASE WHERE ID=$id" ;
if(!$result = odbc_do($connectionstring, $query))
{
die('There was a database error in the query: ' . odbc_errormsg());
}
while ($row = odbc_fetch_array($result))
{
$ID = $row['ID'];
$NAME = $row['NAME'];
$LAST_NAME = $row['LAST_NAME'];
}
?>FE wrote:Another question:
I’ve got 3 variables ($ID1, $ID2, $ID3) containing (152,168,335, respectively)
What would the php command be to make a variable = 152-168-335 and not 655 (=152+168+355)
Code: Select all
<?php
$var = $ID1 . '-' . $ID2 . '-' . $ID3;
?>