为我的数据库 mysql 中的每一行调用一个 php 脚本 [英] call a php script for every row in my database mysql

查看:51
本文介绍了为我的数据库 mysql 中的每一行调用一个 php 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个愚蠢的问题,我很抱歉,但我现在不知道如何为表中的每一行调用 php 脚本.我正在使用 mysql.(我将来会使用 PDO,我知道它更好).这是我的选择"页面(我选择我想要的行):

I'm sorry if it's a stupid question, but I don't now how to call a php script for every row from my table. I'm using mysql. (I will use PDO in the future, I know it's better). this is my "select" page ( where I select the rows that I want):

<?php
include "util.php";
conn();
$SQL = "SELECT * FROM profiles where name='beatrice'"; //it's just an example
$result = mysql_query($SQL);

    while ($db_field = mysql_fetch_assoc($result)) {
                        $id= $db_field['id'] ;
                        $nome= strtolower($db_field['name']);
                        $cognome= strtolower($db_field['surname']);
                        $filenome= strtolower($db_field['filename']);
                        $cf= $db_field['cf'];
                        $dir1 = mb_substr($cf, 0, 8);
                        $dir=$id.$dir1;
                        mkdir('test/doc/'.$dir, 0777, TRUE);
                        mkdir('test/doc/'.$dir.'/foto', 0777, TRUE);
                        mkdir('test/doc/'.$dir.'/thumbnails', 0777, TRUE);
                        header('Location:renamer.php?dir='.$dir.'&nome='.$nome.'&filenome='.$filenome.'&id='.$id);
    }

    ?>

标题位置不起作用,所以我正在寻找另一种方法来做到这一点.

Header location doesn't work, so I'm searching for another way to do it.

推荐答案

您可以使用 CURL 调用.

或者只是调用一个函数来在循环中做你想做的事情.

OR just call a function to do what you want within the loop.

因此只需创建一个函数(从 renamer.php 中的功能),它将 URL 参数作为参数,然后就可以了!

So just create a function (from the functionality within renamer.php) which takes the URL params as the arguments and off you go!

如果您真的需要在后台执行此操作,请查看 - http://php.net/manual/en/function.pcntl-fork.php - 如果您关闭,它将启动一个新的 PHP 进程来执行某些操作这条路线会变得复杂,你的任务需要以某种方式报告,以便你知道什么已经/还没有完成:)

If you REALLY need to do it in the background look into - http://php.net/manual/en/function.pcntl-fork.php - which will launch a new PHP process to execute something, if you go down this route it will get complicated and your task will need to report in some way so you know what has/has not been done :)

这篇关于为我的数据库 mysql 中的每一行调用一个 php 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆