What are the differences between mysqli_connect and mysqli_pconnect?

0 votes
What is the main difference between them? Can anyone explain me with any sample code?

thank you!!
Mar 27 in PHP by kartik
• 10,990 points
69 views

1 answer to this question.

0 votes

Hello,

mysqli_pconnect() function is used for making a persistence connection with the database that does not terminate when the script ends.

mysqli_connect() function searches any existing persistence connection first and if no persistence connection exists, then it will create a new database connection and terminate the connection at the end of the script.

Sample code:

$DBconnection = mysqli_connect("localhost","username","password","dbname");

// Check for valid connection

if (mysqli_connect_errno())

{

echo "Unable to connect with MySQL: " . mysqli_connect_error();

}

mysqli_pconnect() function is depreciated in the new version of PHP, but you can create persistence connection using mysqli_connect with the prefix p.

Thank You!!

answered Mar 27 by Niroj
• 22,110 points

Related Questions In PHP

0 votes
0 answers

What are the differences in die() and exit() in PHP?

I think both have the same functionality, ...READ MORE

Apr 8 in PHP by kartik
• 10,990 points
23 views
0 votes
1 answer

What are the best way to allow plugins for a PHP application?

Hii, Here is an approach I have  used, it's ...READ MORE

answered Apr 1 in PHP by Niroj
• 22,110 points
24 views
0 votes
1 answer

What is type casting and type juggling in php?

Hey, The way by which PHP can assign ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
48 views
0 votes
1 answer

What is the use of $_REQUEST variable in php?

Hii @kartik, The $_REQUEST variable is used to read the ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
49 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
40 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
33 views
0 votes
1 answer

How to get thumbnail of youtube video from youtube API?

Hii @kartik, If you want the biggest image ...READ MORE

answered Apr 1 in PHP by Niroj
• 22,110 points
108 views
0 votes
1 answer

Error: laravel.log could not be opened?

Hello, Never use 777 for directories on your ...READ MORE

answered Apr 2 in Laravel by Niroj
• 22,110 points
296 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13 in PHP by Niroj
• 22,110 points
67 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,110 points
36 views