Re: Newbie mysql question

From: Date: Fri, 19 Jul 2002 21:37:16 +0000
Subject: Re: Newbie mysql question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-108584@lists.php.net to get a copy of this message
$dbh = mysql_connect($host, $user, $pass); $query = "SELECT id FROM ma_users WHERE user='$PHP_AUTH_USER'"; $results = mysql_db_query($database, $query, $dbh); $row = mysql_fetch_object($results); $id = $row->id; However, I have found it to be beneficial to check assumptions like "the query will only return one piece of data". You might also want to include a couple of lines of code to make sure of that: $num = mysql_num_rows($results); if($num != 1) { // do some error handling } ..mike.. On Fri, 2002-07-19 at 13:47, John Wulff wrote: > If i KNOW this query will only return one "piece" of data, what, php'ly > speaking, must i do to assign it to the var $id? > > SELECT id FROM ma_users WHERE user='$PHP_AUTH_USER' > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#108584) next »