PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label connect. Show all posts
Showing posts with label connect. Show all posts

Monday, October 31, 2022

[FIXED] How I can check if it something available in socket?

 October 31, 2022     c, connect, eof, read-write, sockets     No comments   

Issue

I write a simple application that provide connection between two computers in C. I have a problem with simultaneously reading and writing in socket. I am able to check if user press any key by getch(), but I don't know how to check if it something in socket buffer. When I use read() function it wait until be something in socket. I wanted to check socket buffer and then use read(), but I can't find any function/flag to check this. Maybe is different solution for this problem, perhaps use another thread to read?


Solution

You can use sys/ioctl.h file's method ioctl:

#include <sys/ioctl.h>

...

int count;
ioctl(fd, FIONREAD, &count);

Reference credit : This Answer



Answered By - Kushal
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, February 1, 2022

[FIXED] Cannot connect to mysql database [phpmyadmin]

 February 01, 2022     connect, database, mysql, phpmyadmin, xampp     No comments   

Issue

  • to create databases I'm using xampp->phpyadmin,
  • I have created a database called "dungeons",
  • in my php code Im connecting to MySQL with this code:

    if ($_SERVER["SERVER_ADDR"]=="localhost")
    {
      define("SQL_HOST","localhost");
      define("SQL_DBNAME","dungeons");
      define("SQL_USERNAME",xxx);
      define("SQL_PASSWORD",xxx);
    } else {
      define("SQL_HOST","127.0.0.1");
      define("SQL_DBNAME","dungeons");
      define("SQL_USERNAME", xxx);
      define("SQL_PASSWORD",xxx);
    }
    
    mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD) or die("Cannot connect to mySQL: " . mysql_error());
    mysql_select_db(SQL_DBNAME) or die("Cannot connect to the database: ". mysql_error()); 
    

The error message says

Unknown database 'dungeons', when selecting db.

I don't have any idea where the problem is, since the database is made and I have successfully connected to the mysql with the code.


Solution

The error is correctly saying that the database is not available or not there. First create a new database in phpmyadmin and name it dungeons. After that try your script. Thank you



Answered By - Altaf Hussain
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, December 29, 2021

[FIXED] Connecting PHP to React

 December 29, 2021     connect, lamp, php, reactjs     No comments   

Issue

I've been learning how to use React and I already know substantial PHP. I know that I can use PHP with React since React is only the view in MVC but how do I use PHP with react locally. I have a lamp server running on my Linux machine I want to be able to run it as a backend. Like, let's say I want to make a login screen how do I connect it up. I make the front end in React and the backend in PHP. Do I have to use CORS I'd rather not since, in the end, it's going to be running on the same server.


Solution

You don't need CORS, it seems you are looking for proxy.

Just set your proxy to the listening port of your LAMP API server and then simply use fetch with absolute path from your React app.

Let's say your LAPM server is listening on port 23000

"proxy": "http://localhost:23000",

in package.json file of your React app, then

fetch("/my/api")

will call http://localhost:23000/my/api.



Answered By - Daniele Ricci
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing