コード例 #1
0
ファイル: simpleExample.php プロジェクト: thecsea/mysqltcs
    $connection = new Mysqltcs($db['host'], $db['user'] . "wrong", $db['psw'], $db['db']);
} catch (MysqltcsException $e) {
    print "Error on connection caught<br/>\n";
    print $e->getMessage() . "<br/>\n";
}
print "<h3>Correct data</h3>\n";
//correct connection
try {
    $connection = new Mysqltcs($db['host'], $db['user'], $db['psw'], $db['db']);
    print "No error<br/>\n";
} catch (MysqltcsException $e) {
}
print "<h2>Simple query</h2>\n";
print "<h3>Correct query(show tables)</h3>\n";
//simple query
$results = $connection->executeQuery("show tables");
while ($row = $results->fetch_array()) {
    print $row[0] . "<br/>\n";
}
print "<h3>Error on query</h3>\n";
//if an error is occurred mysqltcs throw an exception
try {
    $results = $connection->executeQuery("No sql");
} catch (MysqltcsException $e) {
    print "Error on query caught<br/>\n";
    print $e->getMessage() . "<br/>\n";
}
print "<h1>Simple operations</h1>\n";
//now we use MysqltcsOperations that allows to make common operations immediately in a specified table
$operations = new MysqltcsOperations($connection, $db['tables']['test1']);
print "<h2>Insert</h2>\n";
コード例 #2
0
ファイル: loggerExample.php プロジェクト: thecsea/mysqltcs
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
use it\thecsea\mysqltcs\Mysqltcs;
use it\thecsea\mysqltcs\SimpleLogger;
use it\thecsea\mysqltcs\MysqltcsException;
require_once __DIR__ . "/../vendor/autoload.php";
$db = (require __DIR__ . "/config.php");
$connection = new Mysqltcs($db['host'], $db['user'], $db['psw'], $db['db'], false);
print "create logger<br>\n";
//you can create your logger that implements MysqltcsLogger
$logger = new SimpleLogger();
$connection->setLogger($logger);
//you can als do in the following way: $connection->setSimpleLogger() and get logger with $connection->getLogger();
print "Simple correct query<br/>\n";
$connection->executeQuery("show tables");
print "Query with error<br/>\n";
try {
    $connection->executeQuery("no sql");
} catch (MysqltcsException $e) {
}
print "Log data<br/>\n";
$data = $logger->getLogArray();
foreach ($data as $ele) {
    print $ele . "<br/>\n";
}
print "if you use simpleLogger, you can also print the log when the query is performed<br/>\n";
$logger->setPrint(true);
$connection->executeQuery("show tables");