Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cliente of connection for slqanywhere/sybase based on PHP class PDO

License

NotificationsYou must be signed in to change notification settings

cagartner/sql-anywhere-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

The development was based on PDO Native Class.

TODO:

  • More tests.

Installation

=================

1- First install sqlanywhere module for PHPClick Here!.

2- Use composer to install this package adding the lines bellow in the require sectionrequire:// ..."require": {"cagartner/SQLAnywhereClient": "dev-master"},// ...

How to use

Bellow have some examples of how to use this class.

ConnectionSQLAnywhereClient::__construct:

<?phprequire'../vendor/autoload.php';useCagartner\SQLAnywhereClient;try {$dns ="uid={user};pwd={password};ENG={database-name};commlinks=tcpip{host={host};port={port}}";$con =newSQLAnywhereClient($dns );    }catch (Exception$e) {echo$e->getMessage();    }?>

Você pode definir duas opções iniciais junto com a conexão, que são as seguintes:auto_commit eis_persistent.You can define two initials configuration params with the connection:auto_commit andis_persistent.

  • auto_commit Enable auto commit, default istrue;
  • is_persistent Define persistent mode, default isfalse;
<?phprequire'../vendor/autoload.php';useCagartner\SQLAnywhereClient;try {$dns ="uid={uid};pwd={password};ENG={};commlinks=tcpip{host={host};port={password}}";$autocommit =false;$persistent =true;$con =newSQLAnywhereClient($dns,$autocommit,$persistent );    }catch (Exception$e) {echo$e->getMessage();    }?>

Executing SQL commandsSQLAnywhereClient::exec():

<?php$sql ="SELECT * FROM users";$result =$con->exec($sql );echo"<pre>";print_r($result->fetch());echo"</pre>";exit;?>

Executing SQL commands with retrieve of dataSQLAnywhereClient::query() :

This method return an array with the data

<?php$sql ="SELECT name, email FROM users";foreach ($con->query($sql )as$result) {print_r($result);    }exit;?>

Retrieve just one lineSQLAnywhereQuery::fetch

Return first row

<?php$sql ="SELECT name, email FROM users";$result =$con->exec($sql );$user =$result->fetch();print_r($user);exit;?>

Data format returns

You can choose how is the format that your data is retrieveSQLAnywhereClient

<?php// Retornar em um array com idexação por numero e coluna    SQLAnywhereClient::FETCH_ARRAY;// Retornar em um array com idexação por coluna    SQLAnywhereClient::FETCH_ASSOC;// Formato Padrão!// Retornar em um array com idexação por coluna    SQLAnywhereClient::FETCH_OBJECT;// Retornar em um array com idexação por linha de dados    SQLAnywhereClient::FETCH_ROW;// Retornar em um array com idexação por colunas    SQLAnywhereClient::FETCH_FIELD;?>

Example:

<?php$sql ="SELECT name, email FROM users";$result =$con->exec($sql );$user =$result->fetch( SQLAnywhereClient::FETCH_OBJECT );print_r($user);exit;?>

Return all rowsSQLAnywhereQuery::fetchAll

Return all selected rows

<?php$sql ="SELECT name, email FROM users";$result =$con->exec($sql );$user =$result->fetchAll();print_r($user);exit;?>

In this method you also can choose the format of return too:

<?php$sql ="SELECT name, email FROM users";$result =$con->exec($sql );$user =$result->fetchAll( SQLAnywhereClient::FETCH_OBJECT );print_r($user);exit;?>

Row countSQLAnywhereQuery::rowCount

Return the count of rows

<?php$sql ="SELECT name, email FROM users";$result =$con->exec($sql );echo"We find" .$result->rowCount() ." itens.";exit;?>

Or withcount alias:

<?php$sql ="SELECT name, email FROM user";$result =$con->exec($sql );echo"We find" .$result->count() ." itens.";exit;?>

Field countSQLAnywhereQuery::fieldCount

Return the total of fields

<?php$sql ="SELECT name, email FROM user";$result =$con->exec($sql );echo"We find" .$result->fieldCount() ." fields.";exit;?>

Last IDSQLAnywhereClient::lastInsertId()

Return the last inserted ID

<?php$sql ="INSERT INTO user  name, email VALUES ('Carlos', 'contato@carlosgartner.com.br')";if ($con->exec($sql )) {echo$con->lastInsertId();    }exit;?>

Prepared StatementSQLAnywhereClient::prepare():

Prepared Statement with?:

<?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:

<?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;?>

Bind ParamSQLAnywherePrepared::bindParam():

<?php$sql ="INSERT INTO users  name, email VALUES (:name, :email)";$stmnt =$con->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;?>

About

Cliente of connection for slqanywhere/sybase based on PHP class PDO

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp