Retrieve Or Fetch Data From Database In Php Mysql Select Data


Introducing: Trending sort You can now choose khổng lồ sort by Trending, which boosts votes that have happened recently, helping khổng lồ surface more up-to-date answers.

Bạn đang xem: Retrieve or fetch data from database in php mysql select data

Trending is based off of the highest score sort và falls back to lớn it if no posts are trending.

Try it Dismiss
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
You need to retrieve a result set from the query, like so:

$set = mysql_query("SHOW DATABASES;");$dbs = array();while($db = mysql_fetch_row($set)) $dbs<> = $db<0>;echo implode("", $dbs);


It"s clear that you"re new to PHP, so here"s a huge tip.

The "mysql" extension is old & busted. Don"t use it, và stop reading any tutorials that tell you it"s the thing lớn use.

Xem thêm: Nghe Chị Em Mách Cách Nấu Cơm Nát Cho Bé Đơn Giản Nhất, Nghe Chị Em Mách Cách Nấu Cơm Nát Chuẩn Tiện

Instead, learn PDO, it works for most database engine and helps you vì chưng the right thing. Here"s an example:

$dbh = new PDO("mysql:host=localhost;user=foo;password=bar;dbname=baz");$statement = $dbh->query("SHOW DATABASES");print_r( $statement->fetchAll() );


Jacob Relkin"s solution is very good.

However, if you are using MySQL 5.x, I would only change one thing:

Instead of using SHOW DATABASES; I would use this query

SELECT schema_name FROM information_schema.schemata;


To danh sách just the useful Databases, và not the system ones:

$query = "SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ("information_schema", "mysql", "performance_schema")";$result = mysqli_query($link, $query) or die(mysqli_error($link));$dbs = array();while($db = mysqli_fetch_row($result)) $dbs<> = $db<0>;echo implode("", $dbs);Your MySQL user should have full access, otherwise you will see only the databases where you have at least read permissions.


you"re getting a query result set. You need to retrieve the result rows like this:

$r = mysql_query("SHOW DATABASES");while ($row = mysql_fetch_assoc($r)) print_r($row);that aught to vày it

Thanks for contributing an answer to Stack Overflow!

Please be sure khổng lồ answer the question. Provide details & share your research!

But avoid

Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy và cookie policy

Not the answer you're looking for? Browse other questions tagged php mysql or ask your own question.

mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... Expects parameter 1 to be resource
Site design / logo sản phẩm © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.6.27.42462

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.