EngineGP/system/library/sql.php

86 lines
1.9 KiB
PHP
Raw Normal View History

2023-03-04 23:45:46 +00:00
<?php
2023-05-05 01:17:19 +00:00
if (!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://' . $_SERVER['SERVER_NAME'] . '/404'));
class mysql
{
var $sql_id = false;
var $sql_connect = false;
var $query = false;
var $query_id = false;
var $mysqlerror = '';
public function connect_mysql($c, $u, $p, $n)
2023-03-04 23:45:46 +00:00
{
2023-05-05 01:17:19 +00:00
if (!$this->sql_id = @new mysqli($c, $u, $p, $n)) {
if (!ERROR_DATABASE)
return NULL;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$this->out_error(mysqli_connect_error());
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
mysqli_query($this->sql_id, "/*!40101 SET NAMES 'utf8' */");
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$this->sql_connect = true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public function query($query)
{
if (!$this->sql_connect)
$this->connect_mysql(CONNECT_DATABASE, USER_DATABASE, PASSWORD_DATABASE, NAME_DATABASE);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (!($this->query_id = mysqli_query($this->sql_id, $query)) and (mysqli_error($this->sql_id) and ERROR_DATABASE))
$this->out_error(mysqli_error($this->sql_id), $query);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $this->query_id;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public function get($query_id = false)
{
if (!$query_id)
$query_id = $this->query_id;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$get = mysqli_fetch_assoc($query_id);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $get;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public function num($query_id = false)
{
if (!$query_id)
$query_id = $this->query_id;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return mysqli_num_rows($query_id);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public function id()
{
return mysqli_insert_id($this->sql_id);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public function esc()
{
mysqli_close($this->query_id);
mysqli_stmt_close($this->sql_id);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
private function out_error($error, $query = '')
{
global $go;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($go)
sys::outjs(array('e' => 'Query: ' . $query . '<br>Error:<br>' . $error));
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($query != '')
echo 'Query: ' . $query . '<br>';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
echo 'Error:<br>' . $error;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
exit();
2023-03-04 23:45:46 +00:00
}
2023-05-05 01:17:19 +00:00
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$sql = new mysql;
2023-03-04 23:45:46 +00:00
?>