There are three informations, which you might want to have from MySQLi.
- Data about the aftereffect of inquiries − This incorporates number of records influenced by any SELECT, UPDATE or DELETE articulation.
- Data about tables and data sets − This incorporates data relating to the construction of tables and data sets.
- Data about the MySQLi worker − This incorporates current status of information base worker, form number and so forth
It's exceptionally simple to get all these data at mysqli brief, however while utilizing PERL or PHP APIs, we need to call different APIs expressly to get all these data. Following area will tell you the best way to get this data.
Obtaining the Number of Rows Affected by a Query
PERL Example
In DBI contents, the influenced columns check is returned by do( ) or by execute( ), relying upon how you execute the question −
# Method 1
# execute $query using do( )
my $count = $dbh->do ($query);
# report 0 rows if an error occurred
printf "%d rows were affected\n", (defined ($count) ? $count : 0);
# Method 2
# execute query using prepare( ) plus execute( )
my $sth = $dbh->prepare ($query);
my $count = $sth->execute ( );
printf "%d rows were affected\n", (defined ($count) ? $count : 0);
PHP Example
In PHP, conjure the mysqli_affected_rows( ) capacity to discover the number of lines a question changed −
$result_id = mysqli_query ($query, $conn_id);
# report 0 rows if the query failed
$count = ($result_id ? mysqli_affected_rows ($conn_id) : 0);
print ("$count rows were affected\n");
Listing Tables and Databases
This is not difficult to list down all the data sets and tables accessible with data set worker. Your outcome might be invalid in the event that you don't have adequate advantage.
Aside from the strategy I have referenced underneath, you can utilize SHOW TABLES or SHOW DATABASES questions to get rundown of tables or data sets either in PHP or in PERL.
PERL Example
# Get all the tables available in current database.
my @tables = $dbh->tables ( );
foreach $table (@tables ){
print "Table Name $table\n";
}
PHP Example
<?php
$servername = "localhost:3306";
$username = "root";
$password = "";
$dbname = "TUTORIALS";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo"Database connected";
$sql="SHOW DATABASES";
if (!($result = mysqli_query($conn,$sql))) {
printf("Error: %s\n", mysqli_error($conn));
}
while( $row = mysqli_fetch_row( $result ) ){
if (($row[0]!="information_schema") && ($row[0]!="mysql")) {
echo $row[0]."\r\n";
}
}
$conn->close();
?>
Getting Server Metadata
There are following orders in MySQL which can be executed either at mysql brief or utilizing any content like PHP to get different significant informations about data set worker.
Sr.No. | Command & Description |
---|---|
1 |
SELECT VERSION( ) Server version string |
2 |
SELECT DATABASE( ) Current database name (empty if none) |
3 |
SELECT USER( ) Current username |
4 |
SHOW STATUS Server status indicators |
5 |
SHOW VARIABLES Server configuration variables |