php msqli将记录从一个数据库移动到另一个数据库

时间:2018-11-15 21:08:55

标签: php sql database

我正在尝试将记录从一个数据库复制到另一个数据库。两者都位于具有相同凭据的本地主机,只有数据库名称不同。 在PhpMyAdmin中,我可以使用它,并且运行良好:

INSERT INTO warszawa.typy_pojazdow (typ, nazwa)
       SELECT type, description from rfid.vehicle_types

从php级别,我不知道如何在两个对象上同时运行该查询:

    $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
    $polaczenie2 = new mysqli($host, $db_user, $db_password, $db_name2);

    if ($polaczenie->connect_errno!=0)
    {
        echo "Error: ".$polaczenie->connect_errno;
    }
    else
    {
        $select = $polaczenie && $polaczenie2->query("INSERT INTO warszawa.typy_pojazdow (typ, nazwa ) SELECT type, description from rfid.vehicle_types");
    }

请帮助

1 个答案:

答案 0 :(得分:0)

如果同一个$ db_user可以访问两个数据库,则不需要2个连接。

<ActionBar title="Camera" >

</ActionBar>
<ScrollView orientation="horizontal">
<GridLayout rows="auto, *, auto, auto,auto">

        <StackLayout row="0" orientation="vertical" padding="10">
            <StackLayout orientation="horizontal" padding="10">
                <Label text="saveToGallery"></Label>
                <Switch [(ngModel)]="saveToGallery"></Switch>
            </StackLayout>
            <StackLayout orientation="horizontal" padding="10">
                <Label text="keepAspectRatio"></Label>
                <Switch [(ngModel)]="keepAspectRatio"></Switch>
            </StackLayout>
            <StackLayout orientation="horizontal" padding="10">
                <Label text="width"></Label>
                <TextField hint="Enter width" keyboardType="number" [(ngModel)]="width" class="input"></TextField>
                <Label text="height"></Label>
                <TextField hint="Enter height" keyboardType="number" [(ngModel)]="height" class="input"></TextField>
            </StackLayout>
        </StackLayout>
    
        <Image row="1" [src]="cameraImage" stretch="aspectFit" margin="10"></Image>
        <TextView row="2" [(ngModel)]="labelText" editable="false"></TextView>>
        <Button row="3" text="Take Picture" (tap)='onTakePictureTap($event)' padding="10"></Button>
        <Button row="4" text="Done" (tap)="onDoneTakePicture()"  ></Button>
    </GridLayout> 
</ScrollView>