$a = ['a' => 'aa', 'b' => 'bb', 'c' => 'cc', 'd' => 'dd'];
$b = ['a' => 'aa', 'b' => 'bb', 'c' => 'cc', 'd' => 'ddd'];
foreach($a as $k => $v) {
if(!array_key_exists($k, $b)) {
echo "Нет ключа {$k}\n";
}
}
$conn = stream_socket_accept($socket)
while (strlen($data=fread($conn,1024)) > 0) {
$result .= $data;
}
fclose($conn);
$save=new Db($result);
fclose($socket);
while($conn = stream_socket_accept($socket)) {
while (strlen($data=fread($conn,1024)) > 0) {
$result .= $data;
}
fclose($conn);
$save=new Db($result);
fclose($socket);
}
$users=users_table_html();
echo json_encode($users);
function get_users(){
global $db;
$query = "SELECT t.ID_Teacher,t.Surname,t.Name,t.Patronymic
FROM Teachers t
LEFT JOIN Users u
ON t.ID_Teacher=u.ID_User";
$result = mysqli_query($db, $query);
$data = null;
while($row = mysqli_fetch_assoc($result)){
$data[] = $row;
}
return $data;
}
function users_table_html() {
$data = get_users();
$html = "<table>";
foreach($data as $value) {
$html .= "<tr>";
$html .= "<td>{$value['firstname']}</td>";
$html .= "<td>{$value['lastname']}</td>";
$html .= "</tr>";
}
$html .= "</table>";
}
function getStudents() {
$.ajax({
url: 'getUser.php',
dataType: "json",
}).done(function(studentsList) {
$("#students").html(studentsList);
}).fail(function() {
alert('Ошибка запроса к серверу!');
});
}
getStudents();
$socket = stream_socket_server("tcp://localhost:15689", $errno, $errstr);
stream_set_blocking($socket,0);
stream_set_timeout($socket,0);
set_time_limit(0);
if (!$socket) {
echo "$errstr ($errno)<br />\n";
} else {
$conn = stream_socket_accept($socket)
while (strlen($data=fread($conn,1024)) > 0) {
$result .= $data;
}
fclose($conn);
$save=new Db($result);
fclose($socket);
}
class Db{
public $host;
public $root;
public $password;
public $database;
public $data;
public function __construct($data)
{
$this->data=$data;
$this->host='localhost';
$this->root='root';
$this->password='12345';
$this->database = 'db';
$this->connect();
}
public function connect(){
$link=mysqli_connect($this->host, $this->root, $this->password, $this->database)
or die("Ошибка " . mysqli_error($link));
$this->insert($link);
}
public function insert($link){
$sql = mysqli_query($link,"INSERT INTO `time_load` (`text`) VALUES ('$this->data')");
$this->closeConnection($link);
}
public function closeConnection($link){
mysqli_close($link);
}
}