The INFORMATION_SCHEMA is the best way to get the columns of a table in MySQL. mysql_fetch_row fetches one row of data from the result associated with the specified result identifier. To request a different return style, specify one of the following constants as the first parameter when you call the PDOStatement::fetch method: PDO::FETCH_ASSOC Returns an array indexed by column name as returned in your result set. It is my understanding that a mysql_fetch_array will only return 1 row unless it is used in conjunction with a while loop, which then should return all rows. mysqli_fetch_row() return a single row from the number of records available in the database. PHP and MySQL Code for the above table Then, you can get rows data with the fetch() methods and their FETCH constants.. I am using a while loop to attempt to extract data from two columns in all of the rows of the table. This function is similar to the mysqli_fetch_row(), except that, it will return an array of row information containing column values are indexed with the column name. if you fetch a row with an integer column, the corresponding value for that column and row will still be stored as a string in the array returned by mysql_fetch_row. In the example code snippet, we will show you how to get and show the column names from a table using PHP and MySQL. I may indeed be the only one ever to encounter this - however if you have a myisam table with one row, and you search with valid table and column name for a result where you might expect 0 rows, you will not get 0, you will get 1, which is the myisam optimised response when a table has 0 or one rows. The mysqli_fetch_row() function returns a row from a recordset as a numeric array. The row is returned as an array. Each result column … It's worth noting that the MySQLi functions (and, I presume, the MySQL functions) fetch a string regardless of the MySQL data type. Note: . Returns an numerical array of strings that corresponds to the fetched row, or false if there are no more rows. PDOStatement::fetchColumn() should not be used to retrieve boolean columns, as it is impossible to distinguish a value of false from there being no more rows to retrieve. I am using php to display the data of the two columns id & product_name in each row. By default, PDO returns each row as an array indexed by the column name and 0-indexed column position in the row. Mysql_fetch_array will return the first row in a Mysql resource in the form of an associative array and columns of the MySQL result can be accessed by using the column names of the table. Select data in a MySQL table Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works). if we want to retrieve all the rows of the table then we must put this function inside the while loop. The fetch() method; To select data in a MySQL table, use the SELECT query, and the PDO query() method. Fetch data using mysqli_fetch_row( ) function. I have two tables, and they share similar column names. So the result type is an associative array where each column name and values of a single row are associated together as name, value pairs. E.g. PHP fetch a specific value that begins with a given number from a string with letters and numbers? Returns a single column from the next row of a result set or false if there are no more rows.. Return only the first 15 characters from a column with string values in MySQL; MySQL query to remove special characters from column values? If two or more columns of the result have the same field names, the last column will take precedence. MySQL Query to Get Column Names The following query will find the column names from a table in MySQL and returns all the columns of the specified table. Use PDOStatement::fetch… Fetch specific rows from a MySQL table with duplicate column values (names)? Possible Duplicate: How to fetch result from MySQL row with multiple same-name columns with PHP? at a time it return only the first row of the result set. Getting Row data by mysql_fetch_array.