Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
pdo-simulation-class/pdo.simulation.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
86 lines (65 sloc)
2.26 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Gabriel Conceição - PDO Simulation | Workaround for webserver no support | |
https://github.com/gabrielpconceicao/pdo-simulation-class */ | |
class PDO { | |
public $_conn = ''; | |
public $_query = ''; | |
public $_request = ''; | |
public $_data = array(); | |
public $_arguments = ''; | |
public $_charset = ''; | |
const FETCH_ASSOC = 'FETCH_ASSOC'; | |
const PARAM_STR = 'PARAM_STR'; | |
const PARAM_INT = 'PARAM_INT'; | |
function __construct( $args ) { | |
$this->_arguments = explode(";", $args ); | |
foreach( $this->_arguments as $key => $val ){ | |
if( strpos( $val, 'charset=') !== false ) | |
$this->_charset = str_replace( 'charset=', '', $val); | |
} | |
} | |
public function bindValue( $field, $data, $type ) { | |
if( $type == 'PARAM_INT' && gettype( $data ) != 'string' ) | |
$this->_query = str_replace( $field, $data, $this->_query ); | |
else | |
$this->_query = str_replace( $field, "'".$data."'", $this->_query ); | |
} | |
public function bindParam( $field, $data, $type ) { | |
if( $type == 'PARAM_INT' && gettype( $data ) != 'string' ) | |
$this->_query = str_replace( $field, $data, $this->_query ); | |
else | |
$this->_query = str_replace( $field, "'".$data."'", $this->_query ); | |
} | |
public function prepare( $q ) { | |
$this->_conn = mysql_connect( 'localhost', 'root', 'pass' ); | |
mysql_set_charset( $this->_charset, $this->_conn); | |
mysql_query("SET NAMES '".$this->_charset."'"); | |
mysql_query("SET CHARACTER SET ".$this->_charset ); | |
mysql_query("SET COLLATION_CONNECTION = '".$this->_charset."_unicode_ci'"); | |
mysql_select_db( 'database' ); | |
$this->_query = $q; | |
return $this; | |
} | |
public function execute() { | |
$this->_data = array(); | |
$this->_request = mysql_query( $this->_query ); | |
while ( $row = mysql_fetch_assoc( $this->_request ) ) { | |
array_push( $this->_data, $row ); | |
} | |
$this->_request = mysql_query( $this->_query ); | |
return $this->_data; | |
} | |
public function fetch() { | |
return mysql_fetch_assoc( $this->_request ); | |
} | |
public function fetchAll() { | |
return $this->_data; | |
} | |
public function setAttribute(){ | |
return $this; | |
} | |
public function rowCount(){ | |
return mysql_num_rows( $this->_request ); | |
} | |
} | |
?> |