logo
down
shadow

PHP - Where should mysql_close() be put in if-else clause?


PHP - Where should mysql_close() be put in if-else clause?

By : Hagai
Date : November 22 2020, 09:00 AM
fixed the issue. Will look into that further I have those lines of code: , how about this?
code :
if (mysqli_num_rows($rs) > 0) {
    //do some stuff
    $redirect = 'result_sv.php';
} else {
    $redirect = 'index.php?message=Failed!';
}

mysqli_free_result($rs);
mysqli_close($con);
header("location:".$redirect);


Share : facebook icon twitter icon
mysql_free_result() or mysql_close()

mysql_free_result() or mysql_close()


By : Mav_dhaiwat
Date : March 29 2020, 07:55 AM
I wish did fix the issue. This two functions do two completely different things.
MySql_Close() will close the connection to the database server, but that is done automatically at the end of your script. So unless you only need the DB at the beginning to pull some data out and you are then processing the data for a long time, there is no need to close the connection manually.
Do I really need to do mysql_close()

Do I really need to do mysql_close()


By : Randy Doank
Date : March 29 2020, 07:55 AM
may help you . In most cases calling mysql_close will not make any difference, performance-wise. But it's always good practice to close out resources (file handles, open sockets, database connections, etc.) that your program is no longer using.
This is especially true if you're doing something that may potentially take a few seconds - for instance, reading and parsing data from a REST API. Since the API call is going over the line, negative network conditions can cause your script to block for several seconds. In this case, the appropriate time to open the database connection is after the REST call is completed and parsed.
Do I need to use mysql_close(connection)?

Do I need to use mysql_close(connection)?


By : Idevelor
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further No, this won't help you if you close it at the end of the script. mysql_close() is just useful in case you want to free up resources before you end your script, because your connection is closed as soon as execution of the script ends
What mysql_close() does exactly?

What mysql_close() does exactly?


By : supertrip86
Date : March 29 2020, 07:55 AM
seems to work fine mysqli_close() closes the connection to the database for that specific page ONLY, there is nothing such as disconnecting the website from database which has to be connected again to work, a new connection is started on each page and the connection is automatically closed once the execution ends. mysqli_close() will close it before the execution ends, so to demonstrate this
code :
<?php
// connection starts here
mysqli_query($link, "whatever stuff you need to do");
?>
// The connection is closed here 
<?php
// connection starts here
mysqli_query($link, "whatever stuff you need to do");
mysqli_close($link); // the connection is closed here 
// do whatever more stuff you have to do that are unrelated to the database
?>
<?php
echo 'Hi';
echo 'Bye';
exit(); // this is useless because all code has been executed already 
?>
<?php
echo 'Hi';
exit(); // this is useful as it stops the execution of whatever code is below it. 
echo 'Bye';
?>
using mysql_close()

using mysql_close()


By : user3835646
Date : March 29 2020, 07:55 AM
seems to work fine In the manual :
Related Posts Related Posts :
  • Login System with a DB Connection Class don't login. Return with else error for invalid login
  • Laravel 4.2 Simple Session Logic not working
  • PHP : get timezone where time is as specified
  • PHP Override an array on file
  • How to upgrade from drush 7 to drush 8 via Composer
  • Dynamic Modal not displaying in table
  • Can I have multiple sessions at the same in PHP?
  • PHP Multiple Filtering Links
  • PHP - XLSX to CSV adding spaces
  • mySQLi SELECT in PHP with another table's IVs for decrypting table column data
  • Insert Text Field Name or ID as Value in MySQL Column
  • How to record the most common time online of a group of users?
  • Switch from mySQL to mariaDB timestamp messup
  • Generating all 6 character alphanumeric combinations (upper and lower case)
  • PHP: Swap placeholders in string variable for corresponding defined variable values
  • HTTP request failed! with file get contents
  • How can I manipulate include_once string?
  • Database table not created after running plugin:refresh
  • Sphinx Get Word in Result through PHP API
  • Sending xml via soapclient in PHP
  • PHP class extension - skipping the middle class by calling the parent of the parent
  • Save data from contentEditable div with mysqli
  • Generating a PDF with sequential order images FPDF
  • How to make a request with PHPLeague oAuth2 client?
  • MySQL count rows with two duplicate column values
  • How to send a curl request with pem certificate via PHP?
  • Request error when processing form in controller
  • Can't save xml file content in mysql with fopen/fwrite/fclose (php)
  • Read only Title from a page?
  • PHP - make echo permanent and visible to all viewers
  • composer fails on server with redmine installed
  • Using foreach With Variables on Smarty
  • How do you specify single print blocks when looping through a 'for' loop?
  • PHP: $_FILES returns empty
  • Symfony2 associative array in entity
  • How do I log every output from a PHP script from the command line?
  • How to implement this json feed into a database structure?
  • Codeigniter, windows, xampp, how to use htaccess to get rid of trailing slash?
  • How to disable Navbar and footer in Yii2 other layouts
  • Json not encode my Special Character
  • echo if POST length is low
  • Warning: require_once error
  • What is this code meaning...?
  • Send to /dev/null a PHP function "echo" output
  • How to store post details and timestamp in database?
  • php mysql - search a row and concatenate values of every columns to variable string
  • Write a program to get N number of positive non-zero integers, so that the sum and product of these numbers are equal
  • Running two multi line queries in PHP
  • PHP/ASP Trouble understanding
  • Strict standards notices View/Layout class
  • how to have backwards reference on PHP's regex?
  • Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run `php composer.phar install` or define a ZF2_
  • phpDocumentor: DocBlock with @var tags duplicates descriptions
  • how to push an object to an array within an object with PHP
  • Undefined offset error in for loop
  • mysql query logic for fetching data from 3 related tables on certain condition
  • Saving blob video with php
  • SpeckPaypal ZF2 How to edit the CURRENCY CODE?
  • How to filter associated HABTM data with FriendsOfCake Search for CakePHP 3
  • Check ALL $_POST lengths
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co