Jump to content

[SOLVED] Sockets


WorldDrknss

Recommended Posts

I have created a server using sockets similar to: http://us.php.net/manual/en/ref.sockets.php.

I run the script from the command line using php -q /path to php file.

The problem is using mysql queries within the do events.

On my script I replaced

echo "$buf\n"

with my mysql information and a query string.

 

example - parts edited:

do {
$send_socket = socket_accept($socket);
//REMOVED
//REMOVED
do {
	$buff = socket_read($send_socket, 2048);
	if(!$buff = trim($buff)){ continue; }
	if($buff == 'shutdown'){ socket_close($send_socket); break 2; }
	list($username, $chat ) = explode("|", $buff); //EXAMPLE
	$conn=@mysql_connect("SOME SERVER", "SOME USERNAME", "SOME PASSWORD") or die("Could Not Connect to MySQL");
	$database=@mysql_select_db("SOME DATABASE", $conn) or die("Could Not Connect to Database");
	$add_chat = mysql_query("INSERT INTO chat (username, chat) VALUES('$username', $chat')");
	break;
} while (true);
socket_close($send_socket);
} while (true);

but unfortunately the queries will not work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.