How to manipulate PDO in function

Source: Internet
Author: User
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;}


 
  EXEC (' Set CHARACTER set UTF8 '); $dbc->setattribute (Pdo::attr_emulate_prepares, false); Disable prepared statements emulation}catch (Pdoexception $e) {echo $e->getmessage ();}? >


I want to call PDO in function
Do you want to inherit this class from the PDO in which you write class function?

Ask the great God to show how to write!


Reply to discussion (solution)

If not on the basis of global

Contains PDO class files, instantiates classes, and gives parameters.

Contains PDO class files, instantiates classes, and gives parameters.
OK, in addition I would like to ask you, PDO how to splice SQL Ah, such as where 1=1 and Tile=null no value is ignored

Recommend a look at this AH
http://php.xlxz.org/2013/11/370/

 Pdo_query (' show databases '); Var_dump ($sql, $db->dbversion ()); Exit $sql = $db->select (' i.kd K, io.id dk, iil.ii ds ')->from (' Test T ')->leftjoin (' Post P ', ' t.id =? ') , Array (2))->order (' name DESC, id ASC ')->where (Array (' Xin =? And do >? ' = = Array (1,3))->having (Array (' xin ' = ' dkls ')->group (' id ') Limit (3,4)->queryall (); Exit;//var_dump ($sql); $sql = $db->from (' Test ')->insert (' kd ' = ' 233 ', ' dkwe ' = 323);  $sql = $db->from (' Test ')->where (Array (' (DK =? and kd >?) or (DK =? and DDD =?) ' = = 2,3,5,4))->limit (2, 4)->update (Array (' dkddl ', ' = ' d ', ' kdls ' = ' dkdl ')); $sql = $db->from (' test,test ')->select (' Test,test ')->where (array (' id ' = = = Array (3,3,4, 2, 3))->limit (' 3 ', 3)->delete ();


Contains PDO class files, instantiates classes, and gives parameters.
OK, in addition I would like to ask you, PDO how to splice SQL Ah, such as where 1=1 and Tile=null no value is ignored

Where you can just spell a variable and assign a value when you need it.

As needed
$where = "where xxxx=xxx";
Otherwise
$where = "";


$SQL = "SELECT * from XXX $where";

  • 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.