How can I operate pdo in a function?

Source: Internet
Author: User
How to operate pdo in function? the code is as follows: require (".. /inc/pdo. php "); function & nbsp; output ($ action, $ select, $ name) {$ select = $ dbc-& gt; prepare (" select & nbsp; id, how to operate pdo in a function?
The code is as follows:
Require ("../inc/pdo. php ");

Function output ($ action, $ select, $ name ){
$ Select = $ dbc-> prepare ("select id, ztname, zttype, zttime, headimg, riseimg from naszt where 1 = 1 and zttype =: zttype ");
$ Select-> bindValue (": zttype", $ action );
$ Select-> execute ();
$ Result = '';
While ($ row = $ select-> fetch ()){
$ Result. =' ';
$ Result. = '';
$ Result. = '';
$ Result. ='
    ';
    $ Result. ='
  • Test 1
  • ';
    $ Result. ='
  • Test 12
';
$ Result. = ''. $ row ['ztname'].'';
$ Result. = ''. $ row ['zttype'].'';
$ Result. =' 1 recommended date: '. $ row ['zttime'].'

';
}
Return $ result;
}


 Header ("Content-Type: text/html; charset = utf-8 ");
$ Dbtype = 'mysql ';
$ Host = '1970. 0.0.1 ';
$ DbName = 'Nas ';
$ User = '000000 ';
$ Pass = '000000 ';
$ Db = "$ dbtype: host = $ host; dbname = $ dbName ";
Try {
$ Dbc = new PDO ($ db, $ user, $ pass );
$ Dbc-> exec ('set character set utf8 ');
$ Dbc-> setAttribute (PDO: ATTR_EMULATE_PREPARES, false); // disable the simulation of prepared statements
} Catch (PDOException $ e ){
Echo $ e-> getMessage ();
}
?>


I want to call pdo in function
Is it necessary to inherit this class by writing class functions in pdo?

Please advise me how to write it! Share: More

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.