Re: PHP and MYSQL
| From: | James Gadrow | Date: | Wed, 02 May 2007 19:25:26 +0000 |
| Subject: | Re: PHP and MYSQL | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-43527@lists.php.net to get a copy of this message | ||
Chris wrote:
Na Derro Cartwright wrote://Open connection and database $handle = mysql_connect($host, $user, $pass); mysql_select_db($database); //Run query $result = mysql_query("SELECT foo FROM bar"); //Close connection mysql_close($handle); //Show result echo $result; The correct way to do this is: //Open connection and database $handle = mysql_connect($host, $user, $pass); mysql_select_db($database); //Run query $result = mysql_query("SELECT foo FROM bar"); //use resource id returned from query to fetch actual results (note that the 0 is a line number so in the case you have more than 1 result you'll have to use a different method such as mysql_fetch_assoc or something I'd advise you take a look at the documentation @ php.net) $result = mysql_result($result, 0); //Close connection mysql_close($handle); //Show result echo $result; -- Thanks, JimI am currently running php4 with mysql 5. when I try to run a query using the mysql command I recieve and error that reads the resource id and a number. What does that mean?Firstly always cc the list - others will be able to provide their input and others will also learn from the problem/resolution. What is the query? What is the error? If you run it manually through command line mysql or phpmyadmin do you get an error? You're probably doing something like: