Learning with Texts - Fork 2.4.0-fork
Learn foreign languages with texts
Functions | Variables
database_connect.php File Reference

Connects to the database and check its state. More...

Functions

 do_mysqli_query ($sql)
 
 runsql ($sql, $m, $sqlerrdie=true)
 
 get_first_value ($sql)
 
 prepare_textdata ($s)
 
 prepare_textdata_js ($s)
 
 convert_string_to_sqlsyntax ($data)
 
 convert_string_to_sqlsyntax_nonull ($data)
 
 convert_string_to_sqlsyntax_notrim_nonull ($data)
 
 convert_regexp_to_sqlsyntax ($input)
 
 validateLang ($currentlang)
 
 validateText ($currenttext)
 
 validateTag ($currenttag, $currentlang)
 
 validateArchTextTag ($currenttag, $currentlang)
 
 validateTextTag ($currenttag, $currentlang)
 
 getSettingZeroOrOne ($key, $dft)
 
 getSetting ($key)
 
 getSettingWithDefault ($key)
 
 saveSetting ($k, $v)
 
 LWTTableCheck ()
 
 LWTTableSet ($key, $val)
 
 LWTTableGet ($key)
 
 adjust_autoincr ($table, $key)
 
 optimizedb ()
 
 set_word_count ()
 
 parse_japanese_text ($text, $id)
 
 parse_standard_text ($text, $id, $lid)
 
 prepare_text_parsing ($text, $id, $lid)
 
 check_text_valid ($lid)
 
 update_default_values ($id, $lid, $sql)
 
 check_text ($sql, $rtlScript, $wl)
 
 check_text_with_expressions ($id, $lid, $wl, $wl_max, $mw_sql)
 
 splitCheckText ($text, $lid, $id)
 
 reparse_all_texts ()
 
 update_database ($dbname)
 
 check_update_db ($debug, $tbpref, $dbname)
 
 connect_to_database ($server, $userid, $passwd, $dbname)
 
 get_database_prefixes (&$tbpref)
 

Variables

 $DBCONNECTION = connect_to_database($server, $userid, $passwd, $dbname)
 
 $tbpref = null
 
 $fixed_tbpref = get_database_prefixes($tbpref)
 

Detailed Description

Connects to the database and check its state.

Author
https://github.com/HugoFara/ HugoFara

Function Documentation

◆ adjust_autoincr()

adjust_autoincr (   $table,
  $key 
)

Adjust the auto-incrementation in the database.

@global string $tbpref Database table prefix

◆ check_text()

check_text (   $sql,
  $rtlScript,
  $wl 
)

Check a text and display statistics about it.

Parameters
{string}$sql
{bool}$rtlScript
{}$wl
Returns
void

◆ check_text_valid()

check_text_valid (   $lid)

Echo the sentences in a text. Prepare JS data for words and word count.

@global string $tbpref Database table prefix

Returns
void

◆ check_text_with_expressions()

check_text_with_expressions (   $id,
  $lid,
  $wl,
  $wl_max,
  $mw_sql 
)

Check a text that contains expressions.

Parameters
int$idText ID
int$lidLanguage ID
int[]$wlWord length
int$wl_maxMaximum word length
string$mw_sqlSQL-formatted string
Returns
string SQL-formatted query string

@global string $tbpref Database table prefix

◆ check_update_db()

check_update_db (   $debug,
  $tbpref,
  $dbname 
)

Check and/or update the database.

@global mysqli $DBCONNECTION Connection to the database

counter for cache rebuild

◆ connect_to_database()

connect_to_database (   $server,
  $userid,
  $passwd,
  $dbname 
)

Make the connection to the database.

Returns
mysqli|false Connection to the database

@psalm-suppress UndefinedDocblockClass

◆ convert_string_to_sqlsyntax()

convert_string_to_sqlsyntax (   $data)

Prepares a string to be properly recognized as a string by SQL.

Parameters
string$dataInput string
Returns
string Properly escaped and trimmed string. "NULL" if the input string is empty.

◆ convert_string_to_sqlsyntax_nonull()

convert_string_to_sqlsyntax_nonull (   $data)

Prepares a string to be properly recognized as a string by SQL.

Parameters
string$dataInput string
Returns
string Properly escaped and trimmed string

◆ convert_string_to_sqlsyntax_notrim_nonull()

convert_string_to_sqlsyntax_notrim_nonull (   $data)

Prepares a string to be properly recognized as a string by SQL.

Parameters
string$dataInput string
Returns
string Properly escaped string

◆ do_mysqli_query()

do_mysqli_query (   $sql)

Do a SQL query to the database. It is a wrapper for mysqli_query function.

Parameters
string$sqlQuery using SQL syntax

@global mysqli $DBCONNECTION COnnection to the database

Returns
mysqli_result|true

◆ get_database_prefixes()

get_database_prefixes ( $tbpref)

Get the prefixes for the database.

Is $tbpref set in connect.inc.php? Take it and $fixed_tbpref=1. If not: $fixed_tbpref=0. Is it set in table "_lwtgeneral"? Take it. If not: Use $tbpref = '' (no prefix, old/standard behaviour).

Parameters
string | null$tbprefTemporary database table prefix
Returns
0|1 Table Prefix is fixed, no changes possible

◆ get_first_value()

get_first_value (   $sql)

Return the record "value" in the first line of the database if found.

Parameters
string$sqlMySQL query
Returns
string|null

◆ getSetting()

getSetting (   $key)

Get a setting from the database. It can also check for its validity.

Parameters
string$keySetting key. If $key is 'currentlanguage' or 'currenttext', we validate language/text.
Returns
string $val Value in the database if found, or an empty string @global string $tbpref Table name prefix

◆ getSettingWithDefault()

getSettingWithDefault (   $key)

Get the settings value for a specific key. Return a default value when possible

Parameters
string$keySettings key
Returns
string Requested setting, or default value, or ''

@global string $tbpref Table name prefix

◆ getSettingZeroOrOne()

getSettingZeroOrOne (   $key,
  $dft 
)

Convert a setting to 0 or 1

Parameters
string$keyThe input value
string | int$dftDefault value to use, should be convertible to string
Returns
int

@psalm-return 0|1

◆ LWTTableCheck()

LWTTableCheck ( )

Check if the _lwtgeneral table exists, create it if not.

◆ optimizedb()

optimizedb ( )

Optimize the database.

@global string $trbpref Table prefix

◆ parse_japanese_text()

parse_japanese_text (   $text,
  $id 
)

Parse a Japanese text using MeCab and add it to the database.

Parameters
{string}$text Text to parse.
{int}$id Text ID
Returns
void

◆ parse_standard_text()

parse_standard_text (   $text,
  $id,
  $lid 
)

Parse a text using the default tools. It is a not-japanese text.

Parameters
{string}$text Text to parse
{int}$id Text ID
{int}$lid Language ID
Returns
void

◆ prepare_text_parsing()

prepare_text_parsing (   $text,
  $id,
  $lid 
)

Pre-parse the input text before a definitive parsing by a specialized parser.

Parameters
{string}$text Text to parse
{int}$id Text ID
{int}$lid Language ID
Returns
void

◆ reparse_all_texts()

reparse_all_texts ( )

Reparse all texts in order.

@global string $tbpref Database table prefix

◆ runsql()

runsql (   $sql,
  $m,
  $sqlerrdie = true 
)

Run a SQL query, you can specify its behavior and error message.

Parameters
string$sqlMySQL query
string$mSuccess phrase to prepend to the number of affected rows
bool$sqlerrdieTo die on errors (default = TRUE)
Returns
string Error message if failure, or the number of affected rows

◆ saveSetting()

saveSetting (   $k,
  $v 
)

Save the setting identified by a key with a specific value.

Parameters
string$kSetting key
mixed$vSetting value, will get converted to string

@global string $tbpref Table name prefix

Returns
string Error or success message

◆ set_word_count()

set_word_count ( )

Set the number of words for all languages

@global string $tbpref Database table prefix

◆ splitCheckText()

splitCheckText (   $text,
  $lid,
  $id 
)

Parse the input text.

Parameters
string$textText to parse
string$lidLanguage ID (LgID from languages table)
int$idReferences whether the text is new to the database $id = -1 => Check, return protocol $id = -2 => Only return sentence array $id = TextID => Split: insert sentences/textitems entries in DB

@global string $tbpref Database table prefix

Returns
null|string[]

@psalm-return non-empty-list<string>|null

◆ update_database()

update_database (   $dbname)

Update the database if it is using an outdate version.

Parameters
string$dbnameName of the database

@global string $tbpref Database table prefix @global 0|1 $debug Output debug messages.

◆ update_default_values()

update_default_values (   $id,
  $lid,
  $sql 
)

Change the default values for default language, default text, etc...

Parameters
{int}$id New default text ID
{int}$lid New default language ID
{string}$sql
Returns
void

◆ validateLang()

validateLang (   $currentlang)

Validate a language ID

Parameters
string$currentlangLanguage ID to validate
Returns
string '' if the language is not valid, $currentlang otherwise

@global string $tbpref Table name prefix

◆ validateText()

validateText (   $currenttext)

Validate a text ID

Parameters
string$currenttextText ID to validate

@global string '' if the text is not valid, $currenttext otherwise

@global string $tbpref Table name prefix