mysqli_real_escape_string() | MYSQLi Escape String | PHP Example

The simplest way to use the MYSQLi Escape String example looks like this.

<?php

$conn = new mysqli('localhost', 'root', 'pass', 'test');
$srting = "O!-wlearnsmart";
$res = mysqli_real_escape_string($conn, $srting );
echo $res;

?>

In this mysqli_real_escape_string() function allow two-parameter which is a database connection and the other one passes a string. Accordingly, PHP should be used while insert data in the table.

Hence, Keep scrolling down for the next chapter.


mysqli_num_rows() | Check if ResultSet is empty | Example

The simplest way to use check if resultset is empty example looks like this.

<?php	
	
	$conn = new mysqli('localhost', 'username', 'password', 'databasename');
	$sql = 'select * from tableName';
	$query = mysqli_query($conn, $sql );
	
	$rowcount=mysqli_num_rows($query);
	print_r($rowcount);


?>

Here, the mysqli_num_rows() function returns the number of rows in the database table in the result set. Accordantly, you have to apply to check how many rows are available. Above all, show this type of example to check MySQLi num rows along with PHP.

mysqli_num_rows() - How to Check if ResultSet is empty

    $conn = new mysqli('localhost', 'username', 'password', 'databasename');

	$sql = 'select * from TableName';
	$query = mysqli_query($conn, $sql );
	
	$rowcount=mysqli_num_rows($query);
	
	if($rowcount > 0){

		echo 'Not Empty';

	}else{

		echo 'Empty';

	}

Here, you can see conditions that check if the result set is empty or not. Thus, add this PHP code with the mysqli_num_rows() function example.

Hence, Keep scrolling down for the next chapter.

[wlearnsmartcode]


mysqli_fetch_assoc() | Fetch Multiple Rows in PHP | Example

The simplest way to Fetch Multiple Rows in PHP example looks like this.

<?php

$conn = mysqli_connect("localhost", "username", "password", "database-name");

$query = mysqli_query($conn, "SELECT * FROM table-name");

$row = mysqli_fetch_assoc($query);

print_r($row);

?> 

In this section, fetch single rows from the database. In the above, the first query to relate connectivity database and another one mysqli_query() this function for run query along with the condition. Thus, the mysqli_fetch_assoc() function use retrieve data from the data then store a variable.

mysqli_fetch_assoc() - How to Fetch Multiple Rown From the Database in PHP

<?php
$conn = mysqli_connect("localhost", "username", "password", "database-name");

$query = mysqli_query($conn, "SELECT * FROM student_table");
     while ($row = mysqli_fetch_assoc($query)) {     
		
      print_r($row);   
      
}
?>   

In this section, you can fetch multiple rows from the database in PHP. Also, this code using a while loop to retrieve data. Therefore, whenever get data to apply this mysqli_fetch_assoc() with a while loop. How to Store and Retrieve Image from database in Php

Hence, Keep scrolling down for the next chapter.

[wlearnsmart]

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

Related Post

mysqli_num_rows() | Check if ResultSet is empty | Example

The simplest way to use check if resultset is empty example looks like this. Here, the mysqli_num_rows() function returns the number of rows in the database table in the result set. Accordantly, you have to apply to check how many rows are available. Above all, show this type of example to check MySQLi num rows […]

Read more

mysqli_fetch_assoc() | Fetch Multiple Rows in PHP | Example

The simplest way to Fetch Multiple Rows in PHP example looks like this. In this section, fetch single rows from the database. In the above, the first query to relate connectivity database and another one mysqli_query() this function for run query along with the condition. Thus, the mysqli_fetch_assoc() function use retrieve data from the data […]

Read more

x