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