Methods

This method is automatically called in \Phalcon\Db\Adapter\Pdo constructor.
Call it when you need to restore a database connection.

<?phpusePhalcon\Db\Adapter\Pdo\Mysql;// Make a connection$connection=newMysql(["host"=>"localhost","username"=>"sigma","password"=>"secret","dbname"=>"blog","port"=>3306,]);// Reconnect$connection->connect();

public prepare (mixed $sqlStatement)

Returns a PDO prepared statement to be executed with ‘executePrepared’

<?phpusePhalcon\Db\Column;$statement=$db->prepare("SELECT * FROM robots WHERE name = :name");$result=$connection->executePrepared($statement,["name"=>"Voltron",],["name"=>Column::BIND_PARAM_INT,]);

<?php// Getting all robots with associative indexes only$robots=$connection->fetchAll("SELECT * FROM robots",\Phalcon\Db::FETCH_ASSOC);foreach($robotsas$robot){print_r($robot);}// Getting all robots that contains word "robot" withing the name$robots=$connection->fetchAll("SELECT * FROM robots WHERE name LIKE :name",\Phalcon\Db::FETCH_ASSOC,["name"=>"%robot%",]);foreach($robotsas$robot){print_r($robot);}

<?php// Getting count of robots$robotsCount=$connection->fetchColumn("SELECT count(*) FROM robots");print_r($robotsCount);// Getting name of last edited robot$robot=$connection->fetchColumn("SELECT id, name FROM robots order by modified desc",1);print_r($robot);

<?php// Inserting a new robot$success=$connection->insert("robots",["Astro Boy",1952],["name","year"]);// Next SQL sentence is sent to the database systemINSERTINTO`robots`(`name`,`year`)VALUES("Astro boy",1952);

<?php// Inserting a new robot$success=$connection->insertAsDict("robots",["name"=>"Astro Boy","year"=>1952,]);// Next SQL sentence is sent to the database systemINSERTINTO`robots`(`name`,`year`)VALUES("Astro boy",1952);

<?php// Updating existing robot$success=$connection->update("robots",["name"],["New Astro Boy"],"id = 101");// Next SQL sentence is sent to the database systemUPDATE`robots`SET`name`="Astro boy"WHEREid=101// Updating existing robot with array condition and $dataTypes$success=$connection->update("robots",["name"],["New Astro Boy"],["conditions"=>"id = ?","bind"=>[$some_unsafe_id],"bindTypes"=>[PDO::PARAM_INT],// use only if you use $dataTypes param],[PDO::PARAM_STR]);