A super easy PHP Framework for web development!
https://github.com/exacti/phacil-framework
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.2 KiB
128 lines
3.2 KiB
6 years ago
|
<?php
|
||
3 years ago
|
/*
|
||
|
* Copyright © 2021 ExacTI Technology Solutions. All rights reserved.
|
||
|
* GPLv3 General License.
|
||
|
* https://exacti.com.br
|
||
|
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
|
||
|
*/
|
||
|
|
||
|
namespace Phacil\Framework\Databases;
|
||
|
|
||
|
/**
|
||
|
* Legacy class to connect a MySQL with PHP 5 legacy driver.
|
||
|
*
|
||
|
* Doesn't work with PHP 7+
|
||
|
* @package Phacil\Framework\Databases
|
||
10 months ago
|
* @deprecated 2.0.0 Use MySQLi class driver instead.
|
||
|
* @see \Phacil\Framework\Databases\MySQLi
|
||
3 years ago
|
* */
|
||
9 months ago
|
class MySQL_legacy implements \Phacil\Framework\Databases\Api\DriverInterface {
|
||
10 months ago
|
|
||
|
const DB_TYPE = 'MySQL';
|
||
|
|
||
|
const DB_TYPE_ID = 1;
|
||
|
|
||
6 years ago
|
private $connection;
|
||
|
|
||
9 months ago
|
/** {@inheritdoc} */
|
||
6 years ago
|
public function __construct($hostname, $username, $password, $database, $port = '3306', $charset = 'utf8') {
|
||
1 year ago
|
if (!$this->connection = \mysql_connect($hostname, $username, $password)) {
|
||
1 year ago
|
throw new \Phacil\Framework\Exception('Error: Could not make a database connection using ' . $username . '@' . $hostname);
|
||
6 years ago
|
}
|
||
|
|
||
1 year ago
|
if (!\mysql_select_db($database, $this->connection)) {
|
||
1 year ago
|
throw new \Phacil\Framework\Exception('Error: Could not connect to database ' . $database);
|
||
6 years ago
|
}
|
||
|
|
||
1 year ago
|
\mysql_query("SET NAMES '".$charset."'", $this->connection);
|
||
|
\mysql_query("SET CHARACTER SET ".$charset."", $this->connection);
|
||
|
\mysql_query("SET CHARACTER_SET_CONNECTION=".$charset."", $this->connection);
|
||
|
\mysql_query("SET SQL_MODE = ''", $this->connection);
|
||
6 years ago
|
}
|
||
3 years ago
|
|
||
|
public function isConnected() { }
|
||
6 years ago
|
|
||
2 years ago
|
/**
|
||
9 months ago
|
* {@inheritdoc}
|
||
2 years ago
|
*/
|
||
6 years ago
|
public function query($sql) {
|
||
1 year ago
|
$resource = \mysql_query($sql, $this->connection);
|
||
6 years ago
|
|
||
|
if ($resource) {
|
||
|
if (is_resource($resource)) {
|
||
|
$i = 0;
|
||
|
|
||
|
$data = array();
|
||
|
|
||
1 year ago
|
while ($result = \mysql_fetch_assoc($resource)) {
|
||
6 years ago
|
$data[$i] = $result;
|
||
|
|
||
|
$i++;
|
||
|
}
|
||
|
|
||
1 year ago
|
\mysql_free_result($resource);
|
||
6 years ago
|
|
||
10 months ago
|
/**
|
||
|
* @var \Phacil\Framework\Databases\Object\ResultInterface
|
||
|
*/
|
||
|
$query = \Phacil\Framework\Registry::getInstance()->create("Phacil\Framework\Databases\Object\ResultInterface", [$data]);
|
||
|
$query->setNumRows($i);
|
||
6 years ago
|
|
||
|
unset($data);
|
||
|
|
||
|
return $query;
|
||
|
} else {
|
||
|
return true;
|
||
|
}
|
||
|
} else {
|
||
1 year ago
|
throw new \Phacil\Framework\Exception('Error: ' . \mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql);
|
||
6 years ago
|
}
|
||
|
}
|
||
9 months ago
|
|
||
|
/** {@inheritdoc} */
|
||
6 years ago
|
public function escape($value) {
|
||
1 year ago
|
return \mysql_real_escape_string($value, $this->connection);
|
||
6 years ago
|
}
|
||
9 months ago
|
|
||
|
/** {@inheritdoc} */
|
||
6 years ago
|
public function countAffected() {
|
||
1 year ago
|
return \mysql_affected_rows($this->connection);
|
||
6 years ago
|
}
|
||
|
|
||
9 months ago
|
/** {@inheritdoc} */
|
||
6 years ago
|
public function getLastId() {
|
||
1 year ago
|
return \mysql_insert_id($this->connection);
|
||
9 months ago
|
}
|
||
10 months ago
|
|
||
|
/**
|
||
9 months ago
|
* {@inheritdoc}
|
||
10 months ago
|
*/
|
||
|
public function execute($sql, array $params = [])
|
||
|
{
|
||
|
foreach ($params as $placeholder => &$param) {
|
||
|
$bindParams[] = $this->escape($param);
|
||
|
|
||
|
if (is_string($placeholder))
|
||
|
$sql = str_replace($placeholder, $this->escape($param), $sql);
|
||
|
}
|
||
|
$sql = str_replace(array_keys($params), array_values($bindParams), $sql);
|
||
|
return $this->query($sql);
|
||
|
}
|
||
10 months ago
|
|
||
|
/**
|
||
|
*
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public function getDBType() {
|
||
|
return self::DB_TYPE;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public function getDBTypeId() {
|
||
|
return self::DB_TYPE_ID;
|
||
|
}
|
||
6 years ago
|
}
|