How to display mysql table data tutorial

$mix = mysql_query("SHOW DATABASES;");$dbs = array();while($db = mysql_fetch_row($set)) $dbs<> = $db<0>;emang đến implode("", $dbs);


It"s clear that you"re new khổng lồ PHPhường, so here"s a huge tip.

Bạn đang xem: How to display mysql table data tutorial

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

Instead, learn PDO, it works for most database engine & helps you vị 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.

Xem thêm: 8 Ways To Split And Join Large File Splitter &Amp; Joiner Là Gì

However, if you are using MySquốc lộ 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 mục 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($links, $query) or die(mysqli_error($link));$dbs = array();while($db = mysqli_fetch_row($result)) $dbs<> = $db<0>;echo implode("", $dbs);Your MySquốc lộ user should have full access, otherwise you will see only the databases where you have sầu at least read permissions.


you"re getting a query result mix. You need lớn retrieve sầu the result rows like this:

$r = mysql_query("SHOW DATABASES");while ($row = mysql_fetch_assoc($r)) print_r($row);that aught lớn bởi it

Thanks for contributing an answer to Staông xã Overflow!

Please be sure to answer the question. Provide details và chia sẻ your research!

But avoid

Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; baông chồng them up with references or personal experience.

Xem thêm: Sự Khác Biệt Giữa Khóa Siêu Khóa Là Gì, Khóa Chính Là Gì

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 and 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 khổng lồ be resource
site kiến thiết / biệu tượng công ty © 2021 Staông chồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.4.30.39183

Your privacy

By clicking “Accept all cookies”, you agree Staông xã Exchange can store cookies on your device & discthua kém information in accordance with our Cookie Policy.

Chuyên mục: