joungkyun / mysql-extension-wrapper
pure PHP MySQL extension wrapper
Installs: 1 489
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 6
Forks: 11
Open Issues: 0
Requires
- php: >=4.1.0
- ext-mysqli: *
This package is auto-updated.
Last update: 2025-05-12 20:30:30 UTC
README
The mysql-wrapper api support mysql extension api, and was designed to work best as with mysql extension. If you have PHP7 environment and must need mysql extension api, this is good choise.
License
BSD 2-clause
Requirements
- This wrapper api requires mysqli extension on PHP 4.1 and after
- check with is_resource() about mysql link and mysql result, replace is_myresource() api. For example:
<?php # old code $con = mysql_connect(); if ( ! is_resource($con) ) { die ("connect failed\n"); } # wrapper code $con = mysql_connect(); if ( ! is_myresource($con) ) { die ("connect filed\n"); } ?>
Example
<?php # even if loaded mysql extension, well done. require_once 'mysql-wrapper.php'; $con = @mysql_connect ('localhost', 'user', 'pass'); if ( ! is_myresource ($con) ) { trigger_error(sprintf('Connect error: %s', mysql_error()), E_USER_ERROR); exit; } mysql_select_db('mysql', $con); mysql_set_charset ('utf8', $con); $result = mysql_query ('SELECT * FROM user', $con); if ( ! is_myresource($result) ) { trigger_error(sprintf('Query Error: %s', mysql_error()), E_USER_WARNING); } $rno = mysql_num_rows($result); while ( ($row = mysql_fetch_object($result)) ) { printf("User: %s, Host: %s\n", $row->user, $row->host); } mysql_free_result($result); mysql_close($con); ?>
Composer
first, make composer.json as follow:
{ "require": { "joungkyun/mysql-extension-wrapper": "1.0.*" } }
and, install mysql-extension-wrapper
[user@host project]$ php composer.phpt install Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing joungkyun/mysql-extension-wrapper (1.0.1): Downloading (100%) Writing lock file Generating autoload files [user@host project]$
and, write code as follow:
<?php require_once 'vendor/autoload.php'; echo 'mysql_connect is supported '; if ( function_exists('mysql_connect') ) echo 'YES'; else echo 'NO'; echo "\n"; ?>
Credits
JoungKyun.Kim