php question

mariolu

Member
Licensed User
Longtime User
i am very new to php coding !!

i am using the following php code for remotequery. Can any one tell me how I would modify this to allow
multi one line command to my sql database. I am trying to post multi inserts with one command query!!!


$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error();
}
else
{
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
}
?>
 

Tron

Member
Licensed User
Longtime User
Universal UPDATE/INSERT/REPLACE/DELETE

Hi,
I use this PHP script for Update / Replace / Insert and Delete operations.

B4X:
                   :
  
$con = mysql_connect($databasehost,$databaseusername,$dat abasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$query = file_get_contents("php://input"); 
$sth = mysql_query($query);

if (mysql_errno()) { 
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysql_error(); 
}
else
{

    echo  $sth;  
    mysql_close($con);

}
?>
$sth results: the rows affected

Example for Insert 4 rows:
INSERT INTO `phpbb_acl_groups` (`group_id`, `forum_id`, `auth_option_id`, `auth_role_id`, `auth_setting`) VALUES
(1, 0, 85, 0, 1),
(1, 0, 85, 0, 1),
(1, 0, 93, 0, 1),
(1, 0, 111, 0, 1);



greets Jens
PS the beginning of the script is truncated, but I think you find it in this forum.
 
Last edited:
Upvote 0

Tron

Member
Licensed User
Longtime User
PHP Examples

Hi,
it seemed a little bit difficult to post PHP scripts, so I attached 2 Examples.

1.)
"Query_put.php" could be used to modify any table and it includes a LOG function, which writes continously any sent command in a file !
This could be helpful, if something went wrong

2.)"IpUpdate.php" is a script with a predefined REPLACE operation ( this is a kind of guarantee. Only the specified table could be modified.)
This is my advice: "Don't expose a script, which is able to perform modifying operations to ALL your database tables !!!"

greets Jens
 

Attachments

  • Php.zip
    1.1 KB · Views: 215
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…