PHP Link Database

Source: Internet
Author: User
Tags mysql query

PHP 5 Users can use the MySQL extension,mysqli and pdo_mysql link database, but in the PHP7 to remove the MySQL extension way, (W3school is still this way of linking, embarrassing).

So, in this I just use the back two ways.

First, Mysqli link

$mysqli = new Mysqli (' 127.0.0.1 ', ' root ', ', '), if ($mysqli->connect_error) {die (' Connect error ('. $mysqli Connect_errno. ') '. $mysqli->connect_error);} echo "<p> Connection OK $mysqli->host_info </P>" echo "<p> Server $mysqli->server_info </p > ";

Second, Pdo_mysql link database

try{$pdo = new PDO ("Mysql:host=localhost", ' root ', ');} catch (Pdoexception $e) {echo "Connection fialed: $e->getmessage ()";}

Queries with cache and no cache

The query uses a cached query by default. This means that the results of the query are immediately sent from the MySQL server to PHP and then stored in the PHP parser memory. This allows extra operations like counting the number of rows, moving or looking for the current result pointer.

It also allows for further querying on the same connection and result set. The bad side of cache mode is that large result sets may require a large amount of memory that is occupied until the result set is purged or freed, which is done automatically at the end of the request. The term store result is used to represent the cache mode, and all result sets are saved immediately.

Without a cached MySQL query being executed, a resource is returned immediately, and the data is waiting for the MySQL server to be connected. This is used with less memory on the PHP side, but this time increases the load on the server.

Until all result sets are taken away from the server and no queries are sent that are built on the same connection. Queries that are not cached are also known as usage results.

As you can see from these features, the cache query is used when you only want to get a finite result set, or you know the number of rows to return the result set before reading the result set.

There is no cached query pattern used when you want to return a large amount of data. (Transferred from http://blog.csdn.net/yingzhicai/article/details/50936675)

PHP Link Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.