Linux下nohup命令使用备忘(php下启动后台脚本)

后台运行php脚本,用到了nohup命令;
nohup php receive_test.php & 即可后台一直执行;日志在nohup.out文件里;

遇到报错:
nohup: ignoring input and appending output to ‘nohup.out’
nohup.out文件权限问题;先查看进程,把之前的该脚本进程kill掉;然后修改nohup.out的权限,然后重新执行最上面命令即可;

addBatch is a method in the PHP PDO class that allows you to execute multiple SQL statements in a single call to the database. Here's an example: ``` // Create a PDO object and connect to the database $db = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password'); // Start a transaction $db->beginTransaction(); // Prepare the SQL statements $sql1 = "UPDATE users SET name = 'John' WHERE id = 1"; $sql2 = "UPDATE users SET name = 'Jane' WHERE id = 2"; // Add the SQL statements to the batch $db->prepare($sql1)->execute(); $db->prepare($sql2)->execute(); // Commit the transaction $db->commit(); ``` In this example, we first create a PDO object and connect to the database. We then start a transaction using the `beginTransaction()` method. Next, we prepare two SQL statements using the `prepare()` method and store them in the `$sql1` and `$sql2` variables. We then add these SQL statements to the batch using the `execute()` method. Finally, we commit the transaction using the `commit()` method. The `addBatch()` method is not used in this example because we are using the `execute()` method to add the SQL statements to the batch. However, you can use the `addBatch()` method to add SQL statements to the batch as well. The difference is that `execute()` immediately executes the SQL statement, while `addBatch()` adds it to the batch to be executed later. Here's an example of using `addBatch()`: ``` // Prepare the SQL statements $sql1 = "UPDATE users SET name = 'John' WHERE id = 1"; $sql2 = "UPDATE users SET name = 'Jane' WHERE id = 2"; // Create a PDO object and connect to the database $db = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password'); // Start a transaction $db->beginTransaction(); // Add the SQL statements to the batch $db->prepare($sql1)->addBatch(); $db->prepare($sql2)->addBatch(); // Execute the batch $db->executeBatch(); // Commit the transaction $db->commit(); ``` In this example, we first prepare the SQL statements as before. We then create a PDO object and connect to the database. Next, we start a transaction using `beginTransaction()`. Instead of using `execute()` to add the SQL statements to the batch, we use `addBatch()` to add them. After adding the SQL statements to the batch, we execute the batch using the `executeBatch()` method. Finally, we commit the transaction using the `commit()` method.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值