Client for connection with sybase
Classe para conexão com banco de dados Sybase com PHP baseada na biblioteca sqlanywhere. Class for connection with database Sybase with PHP, created for PHP library SqlAnywhere., (*1)
The development was based on PDO Native Class., (*2)
TODO: - More tests., (*3)
1- First install sqlanywhere module for PHP Click Here!., (*4)
2- Use composer to install this package adding the lines bellow in the require section require
:
// ...
"require": {
"cagartner/SQLAnywhereClient": "dev-master"
},
// ..., (*5)
Bellow have some examples of how to use this class., (*6)
SQLAnywhereClient::__construct
:getMessage(); } ?>
Você pode definir duas opções iniciais junto com a conexão, que são as seguintes: auto_commit
e is_persistent
.
You can define two initials configuration params with the connection: auto_commit
and is_persistent
., (*7)
auto_commit
Enable auto commit, default is true
;is_persistent
Define persistent mode, default is false
;getMessage(); } ?>
SQLAnywhereClient::exec()
:exec( $sql ); echo ""; print_r($result->fetch()); echo ""; exit; ?>
SQLAnywhereClient::query()
:This method return an array with the data, (*8)
query( $sql ) as $result) { print_r($result); } exit; ?>
SQLAnywhereQuery::fetch
Return first row, (*9)
exec( $sql ); $user = $result->fetch(); print_r($user); exit; ?>
You can choose how is the format that your data is retrieve SQLAnywhereClient
, (*10)
Example:, (*11)
exec( $sql ); $user = $result->fetch( SQLAnywhereClient::FETCH_OBJECT ); print_r($user); exit; ?>
SQLAnywhereQuery::fetchAll
Return all selected rows, (*12)
exec( $sql ); $user = $result->fetchAll(); print_r($user); exit; ?>
In this method you also can choose the format of return too:, (*13)
exec( $sql ); $user = $result->fetchAll( SQLAnywhereClient::FETCH_OBJECT ); print_r($user); exit; ?>
SQLAnywhereQuery::rowCount
Return the count of rows, (*14)
exec( $sql ); echo "We find " . $result->rowCount() . " itens."; exit; ?>
Or with count
alias:, (*15)
exec( $sql ); echo "We find " . $result->count() . " itens."; exit; ?>
SQLAnywhereQuery::fieldCount
Return the total of fields, (*16)
<?php $sql = "SELECT name, email FROM user"; $result = $con->exec( $sql ); echo "We find " . $result->fieldCount() . " fields."; exit; ?>
SQLAnywhereClient::lastInsertId()
Return the last inserted ID, (*17)
<?php $sql = "INSERT INTO user name, email VALUES ('Carlos', 'contato@carlosgartner.com.br')"; if ($con->exec( $sql )) { echo $con->lastInsertId(); } exit; ?>
SQLAnywhereClient::prepare()
:Prepared Statement with ?
:, (*18)
<?php $sql = "INSERT INTO users name, email VALUES (?, ?)"; $stmnt = $con->prepare( $sql ); if ($stmnt->execute(array('Carlos', 'contato@carlosgartner.com.br'))) { echo $con->lastInsertId(); } exit; ?>
And this params names:, (*19)
<?php $sql = "INSERT INTO users name, email VALUES (:name, :email)"; $stmnt = $con->prepare( $sql ); if ($stmnt->execute(array( ':name' => 'Carlos', ':email' => 'contato@carlosgartner.com.br' ))) { echo $con->lastInsertId(); } exit; ?>
SQLAnywherePrepared::bindParam()
:prepare( $sql ); $name = "Carlos A."; $email = "contato@carlosgartner.com.br"; $stmnt->bindParam(':name', $name); $stmnt->bindParam(':email', $email); if ($stmnt->execute()) { echo $con->lastInsertId(); } exit; ?>