Error converting mysql_list_tables to mysqli_

Asked

Viewed 221 times

2

I have a page to download a backup of Mysql information, however it is giving the following error since I started migrating from mysql_ for mysqli_:

Fatal error: Cannot use Object of type mysqli as array in /home/.../public_html/library/backup.php on line 25

Before I had added one , inside the key [, ] but made a mistake too.

The error code line is:

$res = mysql_list_tables($mysqli [$dbname]) or die(mysqli_error("erro"));

I couldn’t find a way to replace mysql_list_tables.

  • So, I’m changing all the functions to mysqli and changing as needed, but I couldn’t change the mysql_list_tables, I couldn’t find how to do it properly. all functions of my page are already in msyqli and are working well, just this q is giving problems.

  • thanks for the tip. I’ll change the code and try again.

  • I edited your question to make the issue clearer to other visitors, and to avoid negativity by someone who doesn’t follow the comments, but if you don’t like the editing, you can reverse what I did. (later delete this comment here)

1 answer

4


You can’t mix library functions mysql and mysqli.

It turns out that the library mysqli does not have a function directly equivalent to mysql_list_tables, but it is easy to get the listing using a query simple:

  $res = mysqli_query( $conexao, 'SHOW TABLES' );
  while( $row = mysqli_fetch_array($res) ) $tabelas[] = $row[0];

  print_r( $tabelas );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.