Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to read single record from MySQL

Tags:

php

mysql

What's the best way with PHP to read a single record from a MySQL database? E.g.:

SELECT id FROM games 

I was trying to find an answer in the old questions, but had no luck.

like image 965
neon Avatar asked May 01 '09 12:05

neon


People also ask

How do I get only one record in MySQL?

To return only the first row that matches your SELECT query, you need to add the LIMIT clause to your SELECT statement. The LIMIT clause is used to control the number of rows returned by your query.

How can I get DB single record?

First you connect to your database. Then you build the query string. Then you launch the query and store the result, and finally you fetch what rows you want from the result by using one of the fetch methods.

How do I view a record in MySQL?

The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.


1 Answers

$id = mysql_result(mysql_query("SELECT id FROM games LIMIT 1"),0); 
like image 61
Dan Grossman Avatar answered Sep 21 '22 12:09

Dan Grossman