2017 © Pedro Peláez
 

library mysql

Long-living MySQL connection for daemon.

image

workerman/mysql

Long-living MySQL connection for daemon.

  • Tuesday, March 6, 2018
  • by workerman
  • Repository
  • 5 Watchers
  • 18 Stars
  • 7,419 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 7 Versions
  • 12 % Grown

The README.md

Workerman\Mysql\Connection

Long-living MySQL connection for daemon., (*1)

Install

composer require workerman/mysql, (*2)

Usage

$db = new Workerman\MySQL\Connection($mysql_host, $mysql_port, $user, $password, $db_bname);

// Get all rows.
$db1->select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->query();
// Equivalent to.
$db1->select('ID,Sex')->from('Persons')->where("sex='F'")->query();
// Equivalent to.
$db->query("SELECT ID,Sex FROM `Persons` WHERE sex='M'");


// Get one row.
$db->select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->row();
// Equivalent to.
$db->select('ID,Sex')->from('Persons')->where("sex= 'F' ")->row();
// Equivalent to.
$db->row("SELECT ID,Sex FROM `Persons` WHERE sex='M'");


// Get a column.
$db->select('ID')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->column();
// Equivalent to.
$db->select('ID')->from('Persons')->where("sex= 'F' ")->column();
// Equivalent to.
$db->column("SELECT `ID` FROM `Persons` WHERE sex='M'");

// Get single.
$db->select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->single();
// Equivalent to.
$db->select('ID,Sex')->from('Persons')->where("sex= 'F' ")->single();
// Equivalent to.
$db->single("SELECT ID,Sex FROM `Persons` WHERE sex='M'");

// Complex query.
$db->select('*')->from('table1')->innerJoin('table2','table1.uid = table2.uid')->where('age > :age')
->groupBy(array('aid'))->having('foo="foo"')->orderByASC/*orderByDESC*/(array('did'))
->limit(10)->offset(20)->bindValues(array('age' => 13));
// Equivalent to.
$db->query(SELECT * FROM `table1` INNER JOIN `table2` ON `table1`.`uid` = `table2`.`uid` WHERE age > 13
GROUP BY aid HAVING foo="foo" ORDER BY did LIMIT 10 OFFSET 20“);

// Insert.
$insert_id = $db->insert('Persons')->cols(array(
    'Firstname'=>'abc', 
    'Lastname'=>'efg', 
    'Sex'=>'M', 
    'Age'=>13))->query();
// Equivalent to.
$insert_id = $db->query("INSERT INTO `Persons` ( `Firstname`,`Lastname`,`Sex`,`Age`) 
VALUES ( 'abc', 'efg', 'M', 13)");

// Update.
$row_count = $db->update('Persons')->cols(array('sex'))->where('ID=1')
->bindValue('sex', 'F')->query();
// Equivalent to.
$row_count = $db->update('Persons')->cols(array('sex'=>'F'))->where('ID=1')->query();
// Equivalent to.
$row_count = $db->query("UPDATE `Persons` SET `sex` = 'F' WHERE ID=1");

// Delete.
$row_count = $db->delete('Persons')->where('ID=9')->query();
// Equivalent to.
$row_count = $db->query("DELETE FROM `Persons` WHERE ID=9");

// Transaction.
$db1->beginTrans();
....
$db1->commitTrans(); // or $db1->rollBackTrans();

The Versions

06/03 2018

dev-master

9999999-dev http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql

06/03 2018

v1.0.5

1.0.5.0 http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql

26/12 2017

v1.0.4

1.0.4.0 http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql

21/12 2017

v1.0.3

1.0.3.0 http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql

12/12 2017

v1.0.2

1.0.2.0 http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql

18/03 2017

v1.0.1

1.0.1.0 http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql

04/03 2017

v1.0

1.0.0.0 http://www.workerman.net

Long-living MySQL connection for daemon.

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-pdo *
  • ext-pdo_mysql *

 

pdo mysql pdo_mysql