- mysql_list_dbs
- Description
- Parameters
- Return Values
- Examples
- Notes
- See Also
- User Contributed Notes 4 notes
- mysql_list_dbs
- Описание
- Список параметров
- Возвращаемые значения
- Примеры
- Примечания
- Смотрите также
- User Contributed Notes 4 notes
- PHP: Save MySQL Result in Array
- Numerically indexed array with mysqli_fetch_row
- Associative array with mysqli_fetch_assoc
- The all-rounder mysqli_fetch_array
- About the Author
- Related Topics
- Send HTML5 Canvas as Image to Server
- HTML5 Canvas: Beginner Tutorial Chapter 3 — Rectangles and Circles
- jQuery: Send HTML5 Canvas to Server via Ajax
- HTML5 Canvas: Beginner Tutorial Chapter 2 — Drawing Lines
- Units: SI Prefixes for Powers of Ten
- XLS and XLSX: Maximum Number of Columns and Rows
- jQuery: Read and Change Data Attribute Value
- Important Note
- Participate
mysql_list_dbs
This function was deprecated in PHP 5.4.0, and it and the entire original MySQL extension was removed in PHP 7.0.0. Instead, use either the actively developed MySQLi or PDO_MySQL extensions. See also the MySQL: choosing an API guide. Alternatives to this function include:
Description
Returns a result pointer containing the databases available from the current mysql daemon.
Parameters
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() had been called with no arguments. If no connection is found or established, an E_WARNING level error is generated.
Return Values
Returns a result pointer resource on success, or false on failure. Use the mysql_tablename() function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array() .
Examples
Example #1 mysql_list_dbs() example
// Usage without mysql_list_dbs()
$link = mysql_connect ( ‘localhost’ , ‘mysql_user’ , ‘mysql_password’ );
$res = mysql_query ( «SHOW DATABASES» );
?php
while ( $row = mysql_fetch_assoc ( $res )) echo $row [ ‘Database’ ] . «\n» ;
>
// Deprecated as of PHP 5.4.0
$link = mysql_connect ( ‘localhost’ , ‘mysql_user’ , ‘mysql_password’ );
$db_list = mysql_list_dbs ( $link );
while ( $row = mysql_fetch_object ( $db_list )) echo $row -> Database . «\n» ;
>
?>
The above example will output something similar to:
database1 database2 database3
Notes
Note:
For backward compatibility, the following deprecated alias may be used: mysql_listdbs()
See Also
User Contributed Notes 4 notes
There is no direct equivalent of mysql_list_dbs() as a mysqli_list_dbs() command, but you can query «show databases» instead.
$db_list = mysql_list_dbs($connect); //mysql
$db_list = mysqli_query($connect, «SHOW DATABASES»); //mysqli
The example is wrong in Spanish version.
ERROR: mysql_fetch_assoc() expects parameter 1 to be resource, null given in XXX on line 5
while ($fila = mysql_fetch_assoc($res))
OK.
while ($fila = mysql_fetch_assoc($resultado))
The result pointer contains only the databases for which the mysql_user has the select priviledge granted.
Another alternative to this function is:
SQL Query: SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
- MySQL Functions
- mysql_affected_rows
- mysql_client_encoding
- mysql_close
- mysql_connect
- mysql_create_db
- mysql_data_seek
- mysql_db_name
- mysql_db_query
- mysql_drop_db
- mysql_errno
- mysql_error
- mysql_escape_string
- mysql_fetch_array
- mysql_fetch_assoc
- mysql_fetch_field
- mysql_fetch_lengths
- mysql_fetch_object
- mysql_fetch_row
- mysql_field_flags
- mysql_field_len
- mysql_field_name
- mysql_field_seek
- mysql_field_table
- mysql_field_type
- mysql_free_result
- mysql_get_client_info
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_info
- mysql_insert_id
- mysql_list_dbs
- mysql_list_fields
- mysql_list_processes
- mysql_list_tables
- mysql_num_fields
- mysql_num_rows
- mysql_pconnect
- mysql_ping
- mysql_query
- mysql_real_escape_string
- mysql_result
- mysql_select_db
- mysql_set_charset
- mysql_stat
- mysql_tablename
- mysql_thread_id
- mysql_unbuffered_query
mysql_list_dbs
Данная функция объявлена устаревшей в PHP 5.4.0, и, вместе с модулем MySQL, удалена PHP в 7.0.0. Вместо неё используйте активно развивающиеся модули MySQLi или PDO_MySQL. Так же смотрите раздел MySQL: выбор API. Альтернативы для этой функции:
Описание
Возвращает указатель на результат, содержащий список баз данных, доступных на указанном сервере.
Список параметров
Соединение MySQL. Если идентификатор соединения не был указан, используется последнее соединение, открытое mysql_connect() . Если такое соединение не было найдено, функция попытается создать таковое, как если бы mysql_connect() была вызвана без параметров. Если соединение не было найдено и не смогло быть создано, генерируется ошибка уровня E_WARNING .
Возвращаемые значения
Возвращает resource результата в случае успешного выполнения, или false в случае возникновения ошибки. Используйте функцию mysql_tablename() , чтобы получить данные из результата, или любую другую функцию, работающую с результатами запросов, например mysql_fetch_array() .
Примеры
Пример #1 Пример использования mysql_list_dbs()
// Без использования mysql_list_dbs()
$link = mysql_connect ( ‘localhost’ , ‘mysql_user’ , ‘mysql_password’ );
$res = mysql_query ( «SHOW DATABASES» );?php
while ( $row = mysql_fetch_assoc ( $res )) echo $row [ ‘Database’ ] . «\n» ;
>// Устарело, начиная с PHP 5.4.0
$link = mysql_connect ( ‘localhost’ , ‘mysql_user’ , ‘mysql_password’ );
$db_list = mysql_list_dbs ( $link );while ( $row = mysql_fetch_object ( $db_list )) echo $row -> Database . «\n» ;
>
?>Результатом выполнения данного примера будет что-то подобное:
database1 database2 database3
Примечания
Замечание:
Для обратной совместимости может быть использован следующий устаревший псевдоним: mysql_listdbs()
Смотрите также
- mysql_db_name() — Возвращает название базы данных из вызова к mysql_list_dbs
- mysql_select_db() — Выбирает базу данных MySQL
User Contributed Notes 4 notes
There is no direct equivalent of mysql_list_dbs() as a mysqli_list_dbs() command, but you can query «show databases» instead.
$db_list = mysql_list_dbs($connect); //mysql
$db_list = mysqli_query($connect, «SHOW DATABASES»); //mysqli
The example is wrong in Spanish version.
ERROR: mysql_fetch_assoc() expects parameter 1 to be resource, null given in XXX on line 5
while ($fila = mysql_fetch_assoc($res))OK.
while ($fila = mysql_fetch_assoc($resultado))The result pointer contains only the databases for which the mysql_user has the select priviledge granted.
Another alternative to this function is:
SQL Query: SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
- MySQL
- mysql_affected_rows
- mysql_client_encoding
- mysql_close
- mysql_connect
- mysql_create_db
- mysql_data_seek
- mysql_db_name
- mysql_db_query
- mysql_drop_db
- mysql_errno
- mysql_error
- mysql_escape_string
- mysql_fetch_array
- mysql_fetch_assoc
- mysql_fetch_field
- mysql_fetch_lengths
- mysql_fetch_object
- mysql_fetch_row
- mysql_field_flags
- mysql_field_len
- mysql_field_name
- mysql_field_seek
- mysql_field_table
- mysql_field_type
- mysql_free_result
- mysql_get_client_info
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_info
- mysql_insert_id
- mysql_list_dbs
- mysql_list_fields
- mysql_list_processes
- mysql_list_tables
- mysql_num_fields
- mysql_num_rows
- mysql_pconnect
- mysql_ping
- mysql_query
- mysql_real_escape_string
- mysql_result
- mysql_select_db
- mysql_set_charset
- mysql_stat
- mysql_tablename
- mysql_thread_id
- mysql_unbuffered_query
PHP: Save MySQL Result in Array
When we want to process the result of a MySQL query in PHP, it is often practical, to store the data directly into an array. Impcityant functions in this context are mysqli_fetch_array(), mysqli_fetch_row() and mysqli_fetch_assoc(). In this info, I would like to go over this and explain the difference.
Numerically indexed array with mysqli_fetch_row
The function mysqli_fetch_row() returns a numerically indexed array. This means, that we can access the data, for example, with $arr[1] or $arr[3]:
$res = mysqli_query($db, "SELECT name, city, country FROM tab WHERE = mysqli_fetch_row($res); echo $arr[0]; // name echo $arr[1]; // city echo $arr[2]; // country
As the example shows, the order of the elements in the array corresponds to the order of the fields in the query. So we can use the query to determine how our array should be filled.
Associative array with mysqli_fetch_assoc
The function mysqli_fetch_array() returns an associative array. This means, that the fields can not be addressed with the index number but with the name of the field. And this field name is the name of our column from our MySQL database:
$res = mysqli_query($db, "SELECT name, city, country FROM tab WHERE = mysqli_fetch_assoc($res); echo $arr['name']; // name echo $arr['city']; // city echo $arr['country']; // country
Interesting in this context is the function extract(). This function can automatically create individual variables with the respective name from the array, which are then available to us in the code, as the following example shows:
$res = mysqli_query($db, "SELECT name, city, country FROM tab WHERE = mysqli_fetch_assoc($res); extract($arr); echo $name; // name echo $city; // city echo $country; // country
Also the function list() can be used to make individual variables out of the array, as the following example shows:
$res = mysqli_query($db, "SELECT name, city, country FROM tab WHERE $city, $country) = mysqli_fetch_row($res); echo $name; // name echo $city; // city echo $country; // country
In contrast to extract(), however, with list() we have the option of freely defining what our variables should be called. We can, but don’t have to, stick to the names of the columns in our table.
The all-rounder mysqli_fetch_array
The function mysqli_fetch_array() masters to output the data set both numerically indexed as well as an associative array. This can be controled with the parameters MYSQLI_NUM or MYSQLI_ASSOC.
If you omit the parameter completely or you are using MYSQLI_BOTH, you can use both types of indexes:
$arr = mysqli_fetch_array($res); // equivalent to mysqli_fetch_array($res, MYSQL_BOTH); echo $arr[0]; // name echo $arr['city']; // city echo $arr[2]; // country
Calling mysqli_fetch_array($res, MYSQLI_NUM) is equivalent to the function mysqli_fetch_row($res).
Calling mysqli_fetch_array($res, MYSQLI_ASSOC) is equivalent to the function mysqli_fetch_assoc($res).
About the Author
You can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? — sttmedia.com/contact
Show ProfileRelated Topics
Send HTML5 Canvas as Image to Server
HTML5 Canvas: Beginner Tutorial Chapter 3 — Rectangles and Circles
jQuery: Send HTML5 Canvas to Server via Ajax
HTML5 Canvas: Beginner Tutorial Chapter 2 — Drawing Lines
Units: SI Prefixes for Powers of Ten
XLS and XLSX: Maximum Number of Columns and Rows
jQuery: Read and Change Data Attribute Value
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.