3 Commits

Author SHA1 Message Date
troy grunt
c13739e81f hotfixes 2021-04-01 22:08:16 +02:00
troy grunt
c414ec0917 dürfte passen 2021-04-01 21:24:02 +02:00
troy grunt
0d1c93bdb5 SQL update 2021-04-01 19:17:50 +02:00
6 changed files with 139 additions and 136 deletions

8
.gitignore vendored
View File

@@ -1,5 +1,5 @@
/.buildpath
/.project
/secret.php
/config.php
/.buildpath
/.project
/secret.php
/config.php
/test.php

View File

@@ -1,2 +1,3 @@
# php-func-lib
git submodule add https://git.seemsleg.it/pub/php-func-lib lib
git submodule add https://git.seemsleg.it/ef/php-func-lib lib
test

View File

@@ -1,10 +1,10 @@
<?php
// include ('config.php');
include_once ('sql.php');
$sql = new SQL ();
include_once ('string.php');
include_once ('numbers.php');
include_once ('mail.php');
include_once ('debug.php');
include_once ('markdown.php');
<?php
// include ('config.php');
include_once ('sql.php');
$sql = new SQL ();
include_once ('string.php');
include_once ('numbers.php');
include_once ('mail.php');
include_once ('debug.php');
include_once ('markdown.php');
?>

View File

@@ -1,20 +1,17 @@
<?php
function send_mail($an, $betreff, $text, $ok = '', $error = '') {
include 'secret.php';
$sender = 'noreply@troy-grunt.de';
if (isset ( $_sendermail )) {
$sender = $_sendermail;
}
$header = 'From: ' . $sender . "\r\n";
$header .= 'To: ' . $an . "\r\n";
$header .= 'Content-Type:text/html' . "\r\n";
$header .= 'Content-Transfer-Encoding: 8bit' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion ();
if (mail ( $an, $betreff, $text, $header ) === true) {
echo $ok;
} else {
echo $error;
}
function send_mail($an, $betreff, $text, $ok = '', $error = '')
{
$header = 'From: noreply@isleofhope.de' . "\r\n";
$header .= 'To: ' . $an . "\r\n";
$header .= 'Content-Type:text/html' . "\r\n";
$header .= 'Content-Transfer-Encoding: 8bit' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion();
if (mail($an, $betreff, $text, $header) === true) {
echo $ok;
} else {
echo $error;
}
}

View File

@@ -7,6 +7,4 @@ $_m['pass'] = '';
$_m['data'] = '';
$_m['pre'] = 'efcms2_';
$_m['salt'] = '';
$_sendermail = 'noreply@troy-grunt.de';
?>

213
sql.php
View File

@@ -1,4 +1,12 @@
<?php
/*
* $query = sprintf("SELECT firstname, lastname, address, age FROM friends
* WHERE firstname='%s' AND lastname='%s'",
* mysql_real_escape_string($firstname),
* mysql_real_escape_string($lastname));
*
*
*/
class SQL {
private $h;
private $res = false;
@@ -16,12 +24,95 @@ class SQL {
if (SQL_LOG)
$this->f = fopen ( 'sql.log', 'w' );
$this->h = new mysqli ( $_m ['host'], $_m ['user'], $_m ['pass'], $_m ['data'] );
if ($this->h->connect_errno) {
$this->h = mysqli_connect ( $_m ['host'], $_m ['user'], $_m ['pass'] );
//var_dump ( $this->h );
if (! $this->h) {
return false;
}
mysqli_select_db ( $this->h, $_m ['data'] );
return true;
}
private function prepare($q, $t, $p) {
$t = str_split ( $t );
$v = array ();
$q = str_replace ( "?", "%s", $q );
foreach ( $t as $i => $c ) {
switch ($c) {
case 's' :
$v [] = "'" . mysqli_real_escape_string ( $this->h, $p [$i] ) . "'";
break;
case 'i' :
$v [] = ( int ) $p [$i];
break;
case 'd' :
$v [] = ( double ) $p [$i];
break;
default :
//return false;
}
}
$res = array ();
switch (count ( $p )) {
case 0 :
$res = mysqli_query ( $this->h, $q );
break;
case 1 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0] ) );
break;
case 2 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1] ) );
break;
case 3 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2] ) );
break;
case 4 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3] ) );
break;
case 5 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4] ) );
break;
case 6 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5] ) );
break;
case 7 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6] ) );
break;
case 8 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7] ) );
break;
case 9 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8] ) );
break;
case 10 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8], $v [9] ) );
break;
case 11 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8], $v [9], $v [10] ) );
break;
case 12 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8], $v [9], $v [10], $v [11] ) );
break;
case 13 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8], $v [9], $v [10], $v [11], $v [12] ) );
break;
case 14 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8], $v [9], $v [10], $v [11], $v [12], $v [13] ) );
break;
case 15 :
$res = mysqli_query ( $this->h, sprintf ( $q, $v [0], $v [1], $v [2], $v [3], $v [4], $v [5], $v [6], $v [7], $v [8], $v [9], $v [10], $v [11], $v [12], $v [13], $v [14] ) );
break;
}
//echo 'ERROR:';
//var_dump ( mysqli_error_list ( $this->h ) );
//echo '<br>';
/*
* if (! $res || mysqli_errno ( $this->h )) {
* return false;
* }
*/
return $res;
}
public function get($que, $t = '', $p = array ()) {
// echo $que;
$this->cnt_get ++;
@@ -33,56 +124,23 @@ class SQL {
' ',
''
), $que ) . "\n" . print_r ( $p, true ) . "\n\n" );
$statement = $this->h->prepare ( $que );
switch (count ( $p )) {
case 0 :
break;
case 1 :
$statement->bind_param ( $t, $p [0] );
break;
case 2 :
$statement->bind_param ( $t, $p [0], $p [1] );
break;
case 3 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2] );
break;
case 4 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3] );
break;
case 5 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4] );
break;
case 6 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5] );
break;
case 7 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6] );
break;
case 8 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7] );
break;
case 9 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8] );
break;
case 10 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9] );
break;
}
$statement->execute ();
$res = $this->prepare ( $que, $t, $p );
//var_dump ( $res );
//echo '<hr>';
$ret = array ();
// print_r($statement);
if (isset ( $statement->error ) && $statement->error != '') {
if (! $res) {
if (SQL_LOG)
fputs ( $this->f, $statement->error );
fputs ( $this->f, mysqli_error ( $this->h ) );
return false;
}
$result = $statement->get_result ();
// print_r($result);
while ( $row = $result->fetch_assoc () ) {
while ( $row = $res->fetch_assoc () ) {
$ret [] = $row;
}
//var_dump ( $ret );
//echo '<hr><hr>';
return $ret;
}
public function single($que, $t = '', $p = array ()) {
@@ -119,7 +177,6 @@ class SQL {
public function set($que, $t = '', $p = array (), $id = false) {
// echo $que;
$this->cnt_set ++;
$statement = $this->h->prepare ( $que );
if (SQL_LOG)
fputs ( $this->f, str_replace ( array (
"\n",
@@ -128,72 +185,22 @@ class SQL {
' ',
''
), $que ) . "\n" . print_r ( $p, true ) . "\n\n" );
switch (count ( $p )) {
case 0 :
break;
case 1 :
$statement->bind_param ( $t, $p [0] );
break;
case 2 :
$statement->bind_param ( $t, $p [0], $p [1] );
break;
case 3 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2] );
break;
case 4 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3] );
break;
case 5 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4] );
break;
case 6 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5] );
break;
case 7 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6] );
break;
case 8 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7] );
break;
case 9 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8] );
break;
case 10 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9] );
break;
case 11 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9], $p [10] );
break;
case 12 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9], $p [10], $p [11] );
break;
case 13 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9], $p [10], $p [11], $p [12] );
break;
case 14 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9], $p [10], $p [11], $p [12], $p [13] );
break;
case 15 :
$statement->bind_param ( $t, $p [0], $p [1], $p [2], $p [3], $p [4], $p [5], $p [6], $p [7], $p [8], $p [9], $p [10], $p [11], $p [12], $p [13], $p [14] );
break;
}
$statement->execute ();
if (isset ( $statement->error ) && $statement->error != '') {
$res = $this->prepare ( $que, $t, $p );
if (! $res) {
if (SQL_LOG)
fputs ( $this->f, $statement->error );
fputs ( $this->f, mysqli_error ( $this->h ) );
return false;
}
if ($id) {
return $statement->insert_id;
return mysqli_insert_id ( $this->h );
} else {
return $statement->affected_rows;
return ( bool ) mysqli_affected_rows ( $this->h );
}
}
function __destruct() {
if (SQL_LOG)
$this->h->close ();
// echo 'DESTROY';
mysqli_close ( $this->h );
}
}
?>
?>