I have software or an application on a MacBook called Nano Hotel Booking, I am trying to connect it to my CPanel server but I get the error Unknown collation: 'utf8_general_ci'. Everything else works besides the error for UTF8 I have checked the setting on the Data
`
<?php
$database_host = "localhost";
$database_user = "12345";
$database_password = "12345";
$database_name = "12345";
$db_access_token = "";
$return_format = (isset($_REQUEST['return_format'])) ? $_REQUEST['return_format'] : 'json';
$res = array('success' => true, 'errormsg' => '', 'data' => '');
try
{
$filename = (isset($_FILES['uploadedfile']['name'])) ? $_FILES['uploadedfile']['name'] : '';
if(trim($filename))
{
$upload_dir = 'data';
$ar = explode('___', basename($_FILES['uploadedfile']['name']));
if(sizeof($ar) != 3) throw new Exception('Bad file name '.basename($_FILES['uploadedfile']['name']));
if(!trim($ar[0]) || !trim($ar[1])) throw new Exception('Bad folder name');
if(!trim($ar[2])) throw new Exception('Bad file name '.$ar[2]);
if(!file_exists($upload_dir))
{
if(!#mkdir($upload_dir, 0777)) throw new Exception('Can not create folder '.$upload_dir);
}
$upload_dir .= '/'.trim($ar[0]);
if(!file_exists($upload_dir))
{
if(!#mkdir($upload_dir, 0777)) throw new Exception('Can not create folder '.$upload_dir);
}
$upload_dir .= '/'.trim($ar[1]);
if(!file_exists($upload_dir))
{
if(!#mkdir($upload_dir, 0777)) throw new Exception('Can not create folder '.$upload_dir);
}
$upload_dir .= '/'.trim($ar[2]);
if(file_exists($upload_dir)) #unlink($upload_dir);
if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_dir))
throw new Exception('Can not upload file '.$upload_dir);
} else
{
$params = $_REQUEST;
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if(!$action) throw new Exception('Action not found.');
$enc_request = (isset($_REQUEST['enc_request'])) ? $_REQUEST['enc_request'] : '';
$params = #json_decode(trim(base64_decode($enc_request)));
if($params == false) throw new Exception('Request is not valid');
$params = (array)$params;
// Connect user
$s_key = '';
if(isset($params['db_access_token']))
{
$s_key = $params['db_access_token'];
}
if($s_key !== $db_access_token) throw new Exception('Bad user.');
$controller = new apiController($database_host, $database_user, $database_password, $database_name);
if($action === 'checkconnection') throw new Exception('ok');
if(method_exists($controller, $action) === false ) throw new Exception('Action is invalid.');
$controller->request = $params;
$res['data'] = $controller->$action();
}
} catch(Exception $e)
{
$res['success'] = 0;
$res['errormsg'] = $e->getMessage();
}
switch($return_format)
{
case 'json': print(json_encode($res)); exit; break;
case 'xml': print(arrayToXml($res)); exit; break;
}
class apiController
{
public $request = array();
protected $conn;
public function __construct($host = '', $user = '', $psw = '', $dbname = '')
{
#$this->conn = mysqli_connect($host, $user, $psw, $dbname);
if(!$this->conn) throw new Exception(mysqli_connect_errno().' '.mysqli_connect_error());
#mysqli_query($this->conn, "SET CHARACTER SET utf8_general_ci");
#mysqli_query($this->conn, "set names utf8");
#mysqli_query($this->conn, "SET collation_connection = utf8_general_ci");
}
public function select()
{
$sql = (isset($this->request['sql'])) ? $this->request['sql'] : '';
$array = array();
if(is_array($sql))
{
foreach($sql as $value)
{
$arr = $this->selectOne($value);
$array[] = (sizeof($arr) > 0) ? $arr[0] : array();
}
} else
{
$array = $this->selectOne($sql);
}
if($this->conn) #mysqli_close($this->conn);
return $array;
}
public function selectOne($sql = '')
{
if(!trim($sql)) throw new Exception('Empty sql.');
$offset = (isset($this->request['offset'])) ? (int)$this->request['offset'] : 0;
$limit = (isset($this->request['limit'])) ? (int)$this->request['limit'] : 20;
if($limit) $sql .= ' LIMIT '.$offset.', '.$limit;
$result = mysqli_query($this->conn, $sql);
if(!$result) throw new Exception(mysqli_error($this->conn));
$rows = mysqli_num_rows($result);
if($rows <= 0)
{
mysqli_free_result($result);
mysqli_close($this->conn);
return array();
}
$array = array();
$fields = mysqli_num_fields($result);
while ($row = mysqli_fetch_row($result))
{
$onerow = array();
for ($i=0; $i < $fields; $i++) $onerow[] = $row[$i];
$array[] = $onerow;
}
mysqli_free_result($result);
return $array;
}
public function execute()
{
$sql = (isset($this->request['sql'])) ? $this->request['sql'] : '';
$array = array();
if(is_array($sql))
{
foreach($sql as $value)
{
$array = $this->executeOne($value);
}
} else
{
$array = $this->executeOne($sql);
}
if($this->conn) #mysqli_close($this->conn);
return $array;
}
public function executeOne($sql = '')
{
$lastid = '';
$result = null;
if(!trim($sql)) throw new Exception('Empty sql.');
$str = strtoupper($sql);
if((strpos($str, 'CREATE') !== false)
&& (strpos($str, 'TABLE') !== false)
)
{
$sql = str_ireplace ('AUTOINCREMENT' , 'AUTO_INCREMENT', $sql);
$sql = str_ireplace ('COLLATE NOCASE' , '', $sql);
}
if((strpos($str, 'INSERT') !== false)
&& (strpos($str, 'INTO') !== false)
&& (strpos($str, 'VALUES') !== false)
&& (strpos($str, '(0,') !== false)
)
{
$result = mysqli_query($this->conn, 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"');
if(!$result) throw new Exception(mysqli_error($this->conn));
}
$result = mysqli_query($this->conn, $sql);
if(!$result) throw new Exception(mysqli_error($this->conn));
if((strpos($str, 'INSERT') !== false)
&& (strpos($str, 'INTO') !== false)
&& (strpos($str, 'VALUES') !== false)
)
{
$result = mysqli_query($this->conn, 'SELECT LAST_INSERT_ID()');
if (mysqli_num_rows($result) > 0)
{
while ($row = mysqli_fetch_row($result))
{
$lastid = $row[0];
break;
}
}
}
$array = array();
$array[] = array($lastid);
if($result !== true) mysqli_free_result($result);
return $array;
}
public function getFieldFromSql($sql = '', $def = '')
{
if(!$sql) return $def;
$this->request['offset'] = 0;
$this->request['limit'] = 1;
$arr = $this->selectOne($sql);
if(sizeof($arr) == 0) return $def;
if(sizeof($arr[0]) == 0) return $def;
return $arr[0][0];
}
public function getFieldsFromSql($sql = '', $def = '')
{
if(!$sql) return $def;
$this->request['offset'] = 0;
$this->request['limit'] = 1;
$arr = $this->selectOne($sql);
if(sizeof($arr) == 0) return $def;
return $arr[0];
}
public function getArrayFromSql($sql = '')
{
if(!$sql) return array();
$this->request['offset'] = 0;
$this->request['limit'] = 100000;
return $this->selectOne($sql);
}
public function runScript()
{
$php = (isset($this->request['sql'])) ? trim($this->request['sql']) : '';
$nano = $this;
$php_res = #eval($php);
if($this->conn) #mysqli_close($this->conn);
if(is_array($php_res))
{
if(sizeof($php_res) > 0)
{
if(is_array($php_res[0])) return $php_res;
}
return array($php_res);
}
$array = array();
$array[] = array($php_res);
return $array;
}
}
?>
`
I have tried changing the UTF8 to almost everything else.
Related
public function addcart($request)
{
$patient_id = config('api.current_user.patient_id') ? config('api.current_user.patient_id') : 0;
$patient = Patient::find($patient_id);
$patient_diagnostic_cart = #unserialize($patient->diagnostic_cart);
$response = [];
if (!empty($patient_diagnostic_cart)) {
if (in_array((int)$request->test_id, $patient_diagnostic_cart)) {
// abort(400, "Test allready added");
$message = "Test allready added";
} else {
array_push($patient_diagnostic_cart, (int)$request->test_id);
$patient->diagnostic_cart = serialize($patient_diagnostic_cart);
$patient->save();
$message = "Test added";
}
} else {
$patient_diagnostic_cart = (array)(int)$request->test_id;
$patient->diagnostic_cart = serialize($patient_diagnostic_cart);
$message = "Test added";
$patient->save();
}
$response = [
'message' => $message,
'test_id' => array_values(unserialize($patient->diagnostic_cart)),
];
$data = json_decode(json_encode($response, true));
return $data;
}
I'm trying to run a queue using yii so I can do some tests, but whenever I type the command yii queue/run, no job seems to be put in waiting,
This is to send the information of an ID and status of a job that when the conditions are met, will be ran in the main page
This is the code that sends the data into the queue:
class HorarioController extends Controller
{
public function actionBuscar()
{
$hora = date("H").":00".":00";
$dia = date("N");
$horarios = Horarios_Equipos::find()->all();
foreach($horarios as $horario)
{
echo $horario->id_equipo."\n";
echo $horario->estado."\n";
//enviar a cola
Yii::$app->queue->push(
new HorarioJob([
'id_equipo' => $horario->id_equipo,
'estado' => $horario->estado,
])
);
}
return ExitCode::OK;
}
}
And this is the code that does the action in the queue
public function execute($queue)
{
if($estado == '1'){
if($pin == 1)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDa=ON');
return $this->redirect(['view', 'id' => $id]);
}
elseif ($pin == 2)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDb=ON');
return $this->redirect(['view', 'id' => $id]);
}
elseif ($pin == 3)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDc=ON');
return $this->redirect(['view', 'id' => $id]);
}
elseif ($pin == 4)
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '1';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDd=ON');
return $this->redirect(['view', 'id' => $id]);
}
}
if ($estado == 0){
if ($pin == '1')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDa=OFF');
return $this->redirect(['view', 'id' => $id]);
}
if ($pin == '2')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDb=OFF');
return $this->redirect(['view', 'id' => $id]);
}
if ($pin == '3')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDc=OFF');
return $this->redirect(['view', 'id' => $id]);
}
if ($pin == '4')
{
$equipo = Equipos::find()->where(['id'=>$id])->one();
$equipo->estado = '0';
$equipo->save ();
$curl = new curl\Curl();
$response = $curl->get($equipo->ip.'/gpio/LEDd=OFF');
return $this->redirect(['view', 'id' => $id]);
}
}
}
}
This is what shows when I run yii queue/run:
C:\xampp\htdocs\accontrol>yii queue/run
C:\xampp\htdocs\accontrol>
And if I run yii queue/info it only shows this:
C:\xampp\htdocs\accontrol>yii queue/info
Jobs
- waiting: 0
- delayed: 0
- reserved: 0
- done: 0
As fas as I know the files where the queue functions are written are correct and I should be able to run the queue/run command, at least get an error to see where I'm wrong, but it just doesn't
Found the problem, PHP had the timezone configured incorrectly so when it tried to search for the time on the database it wouldn't match with the time it had configured, had to modify the php.ini document to set the correct timezone, If you're having this problem to enter the php.ini document you can do it via the control panel: in the Apache section click the config button and select the PHP(php.ini)
Then use the find option and search for timezone, and then you may type the timezone of your area, in my case its America/Mexico_City
Heres the link where you can find the timezones: https://www.php.net/manual/es/timezones.php
How can I create login session name? I tried but it didn't work for me.
Here is my code:
loginModel
public function login($name, $pass){
$this->db->select("username", "password");
$this->db->from("users");
$this->db->where("username", $name);
$this->db->where("password", $pass);
$query = $this->db->get();
$ret = $query->row();
if($query->num_rows() == 1){
return true;
}
else {
return false ;
}
}
loginControler;
public function checkLogin(){
$this->form_validation->set_rules("username", "Username", "required");
$this->form_validation->set_rules("password", "Password", "required");
if($this->form_validation->run() == false){
$this->load->view("login");
}
else {
redirect("SiteCont/index");
}
}
public function verifyUser(){
$name = $this->input->post("username");
$pass = $this->input->post("password");
$this->load->model("loginModel");
if($this->loginModel->login($name, $pass)){
return true;
}
else {
$this->form_validation->set_message("verifyUser", "geçersiz kullanıcı adı veya porala");
return false;
}
Only I need something ;
if($this->session->userdata('name')){
//show dashboard
}
else {
//show login
}
in the login page.
loginModel
public function login($name, $pass){
$this->db->select("username", "password");
$this->db->from("users");
$this->db->where("username", $name);
$this->db->where("password", $pass);
$query = $this->db->get();
$ret = $query->row();
if($query->num_rows() == 1){
//set the session data (you can add more values to array according to your needs)
$data = array(
'user_id' => $ret->user_id, //change your actual user id field
);
$this->session->set_userdata($data);
//set the session data
return true;
}
else {
return false ;
}
}
To check
if($this->session->userdata('user_id')){
//redirect to dashboard
}
else{
//redirect to login
}
This will work properly. Change name of variables according to your needs.
My project with PHP and MySql stuck here ,
$searchfriend = "Jason";
$status = query("SELECT status FROM users.profile WHERE name = ?" , $searchfriend );
The above statement works quite well.
When I replace,
$searchfriend = "Jason R"
It's not working. What is the solution ?
I have created my own query function with PDO.
function query()
{
$sql = func_get_arg(0);
$parameters = array_slice(func_get_args(), 1);
static $handle;
if (!isset($handle))
{
try
{
$handle = new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER, USERNAME, PASSWORD);
$handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (Exception $e)
{
trigger_error($e->getMessage(), E_USER_ERROR);
exit;
}
}
$statement = $handle->prepare($sql);
if ($statement === false)
{
trigger_error($handle->errorInfo()[2], E_USER_ERROR);
exit;
}
$results = $statement->execute($parameters);
if ($results !== false)
{
return $statement->fetchAll(PDO::FETCH_ASSOC);
}
else
{
return false;
}
}
I am having an issue with getting this working with PDO not sure how to do it. I tried but kept getting an error. I will keep trying to figure it out. If anyone can point me in the write direction would be a big help
/** Function to Add Product **/
function add_product() {
$data = json_decode(file_get_contents("php://input"));
$prod_name = $data->prod_name;
$prod_desc = $data->prod_desc;
$prod_price = $data->prod_price;
$prod_quantity = $data->prod_quantity;
print_r($data);
$qry = 'INSERT INTO product (prod_name,prod_desc,prod_price,prod_quantity) values ("' . $prod_name . '","' . $prod_desc . '",' .$prod_price . ','.$prod_quantity.')';
$qry_res = mysql_query($qry);
if ($qry_res) {
$arr = array('msg' => "Product Added Successfully!!!", 'error' => '');
$jsn = json_encode($arr);
// print_r($jsn);
}
else {
$arr = array('msg' => "", 'error' => 'Error In inserting record');
$jsn = json_encode($arr);
// print_r($jsn);
}
}
/** Function to Get Product **/
function get_product() {
$qry = mysql_query('SELECT * from product');
$data = array();
while($rows = mysql_fetch_array($qry))
{
$data[] = array(
"id" => $rows['id'],
"prod_name" => $rows['prod_name'],
"prod_desc" => $rows['prod_desc'],
"prod_price" => $rows['prod_price'],
"prod_quantity" => $rows['prod_quantity']
);
}
print_r(json_encode($data));
return json_encode($data);
}
what I tried and I get no data inserting
/** Function to Add Product **/
function add_product() {
$data = json_decode(file_get_contents("php://input"));
$prod_name = $data->prod_name;
$prod_desc = $data->prod_desc;
$prod_price = $data->prod_price;
$prod_quantity = $data->prod_quantity;
print_r($data);
$qry = "INSERT INTO product (prod_name,prod_desc,prod_price,prod_quantity) VALUES (:prod_name,:prod_desc,:prod_price,:prod_quantity)";
$q = $conn->prepare($qry);
$q->execute(array(':prod_name'=>$prod_name,
':prod_desc'=>$prod_desc,
':prod_price'=>$prod_price,
':prod_quantity'=>$prod_quantity,
));
$qry_res = mssql_query($qry);
if ($qry_res) {
$arr = array('msg' => "Product Added Successfully!!!", 'error' => '');
$jsn = json_encode($arr);
// print_r($jsn);
}
else {
$arr = array('msg' => "", 'error' => 'Error In inserting record');
$jsn = json_encode($arr);
// print_r($jsn);
}
}
db setup
<?php
/****** Database Details *********/
$host = "localhost";
$user = "root";
$pass = "";
$database = "shopping";
$con = mysql_connect($host,$user,$pass);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
//echo 'Connected successfully';
mysql_select_db($database,$con);
/*******************************/
?>