0

I have a query where I am getting the list of databases. This is working fine, but I don't know how to execute the queries here in PDO syntax.

$link = mysql_connect('localhost', 'root', '');
$db_list = mysql_list_dbs($link);

$i = 0;
$cnt = mysql_num_rows($db_list);
while ($i < $cnt) {
    echo '<a href='.$i.'>'.mysql_db_name($db_list, $i).$i.' </a><br>';
    $i++;
3

1 Answer 1

0

here sample code with pdo

  $user = 'root';

  $pass = 'root';

  $server = 'localhost';

  $dbh = new PDO( "mysql:host=$server", $user, $pass );

  $dbs = $dbh->query( 'SHOW DATABASES' );

     while( ( $db = $dbs->fetchColumn( 0 ) ) !== false )

      {

        echo $db.'<br>';

      }
Sign up to request clarification or add additional context in comments.

3 Comments

Thank You.. could I know where is the $i as I shown in my code
Could you please help me with passing $i in your code as in my question
I could but first get me useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.