Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

viernes, 28 de marzo de 2025

connection files

database connection file


db_con.php

<?php

// Enable error reporting

//error_reporting(E_ALL);  // Report all errors

error_reporting(E_ERROR | E_PARSE);  // Show only errors and parse errors

ini_set('display_errors', 1);  // Display errors on the web page

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

// Database connection parameters


$host = "172.18.0.3";

$user = "root";

$password = "7133";

$database = "fm";


$mysqli = new mysqli("$host", "$user", "$password", "$database");

// Check for connection errors


if ($mysqli->connect_error) {


    die("Connection failed: " . $mysqli->connect_error);


}


?>






=============select function example=============

 #!/usr/bin/php -q

<?php

require(__DIR__."/getInfo.php");


$PhoneNum="$argv[1]";


$query_val_phone = "SELECT count(phoneNumber) as phoneNumber_num FROM users where phoneNumber='$PhoneNum'";


$registered=select($query_val_phone)[0]['phoneNumber_num'];


if($registered>0){


echo "EXEC Verbose \"User PhoneNum already registered\"\n";



echo "EXEC Goto \"music,100,1\"";

}


else {


echo "EXEC Verbose \"Phone number  $PhoneNum is not registered\"\n";


echo "EXEC Goto \"singup-en,sign-1,1\"";



?>

-----------------

Function for  select.


 <?php

function select($query){
require(__DIR__."/db_con.php");

$result = $mysqli->query($query); 

if (!$result) {  // Check if the query failed

    printf("Error message: %s\n", $mysqli->error);

    exit();

}



$mysqli->close();  

 return $rows = $result->fetch_all(MYSQLI_ASSOC);  
}

?>



================
------------------------

Function for insert


function db_insert($query){

require(__DIR__."/db_con.php");

$result = $mysqli->query($query); 

if (!$result) {  // Check if the query failed

    printf("Error message: %s\n", $mysqli->error);

    exit();

}



$mysqli->close();  
 
}

$query="insert into bla bla";

db_insert($query); 
echo "EXEC Verbose \"$query\"\n";

// php cr_user.php "8297143421" "1982" "5001" "en" "cid"

?>