简体   繁体   English

将2个表中的行从一个数据库复制到其他数据库中的1个表中,但在PHP中使用同一服务器

[英]Copy rows from 2 tables from one database to 1 table in other database but same server in PHP

Hi guys so i have this code but when i run it the new database is empty i really dont know why there is no error log, here is my code: 嗨,大家好,我有这段代码,但是当我运行它时,新数据库为空,我真的不知道为什么没有错误日志,这是我的代码:

<?php
$db_host="localhost";
$db_nombre="****";
$db_nombre2="*****";
$db_usuario="****";
$db_password="*****";
ini_set('memory_limit','500M');

$conexion=mysqli_connect($db_host,$db_usuario,$db_password,$db_nombre);
$conexion2=mysqli_connect($db_host,$db_usuario,$db_password,$db_nombre2);

$data = mysqli_query($conexion,"SELECT v.id, v.userid,v.dueDate, v.status, c.firstname, c.lastname, c.phonenumber FROM tblinvoices v, tblclients c WHERE v.dueDate > '2017-12-10'");
$values = Array();


while ($row = mysqli_fetch_assoc($data)) {

$row[id] = mysqli_real_escape_string($conexion,$row['id']);
$row[userid] = mysqli_real_escape_string($conexion,$row['userid']);
$row[duedate] = mysqli_real_escape_string($conexion,$row['duedate']);
$row[status] = mysqli_real_escape_string($conexion,$row['status']);
$row[firstname] =     mysqli_real_escape_string($conexion,$row['lastname']);
$row[lastname] = mysqli_real_escape_string($conexion,$row['lastname']);
$row[phonenumber] = mysqli_real_escape_string($conexion,$row['phonenumber']);

$values[]='("$row[id]","$row[userid]""$row[duedate]","$row[status]","$row[firstname]","$row[lastname]","$row[phonenumber]")';
}


mysqli_query($conexion2,'INSERT INTO cobranzaSemanal (idInVoice,idUser,dueDate,status,firstName,lastName,phoneNumber) VALUES '.implode(',',$values)."");

?>

Thanks! 谢谢!

Assuming that the username and password are the same for both databases you should be able to combine both queries like this 假设两个数据库的用户名和密码都相同,您应该可以将两个查询合并

$sql="insert into `$db_nombre2`.`cobranzaSemanal` ( `idInVoice`, `idUser`, `dueDate`, `status`, `firstName`, `lastName`, `phoneNumber` )
    (
        select v.`id`, v.`userid`, v.`duedate`, v.`status`, c.`firstname`, c.`lastname`, c.`phonenumber`
        from `$db_nombre`.`tblinvoices` v, `tblclients` c 
        where v.`duedate` > '2017-12-10'
    )";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在PHP MYSQL中将数据库表和每条记录从一个数据库服务器复制到另一个数据库服务器?&gt; - How to copy database tables and each record from one database server to another database server in PHP MYSQL ?> 如何使用PHP将数据库从一台服务器复制到另一台服务器? - How to copy a Database from one server to another server in PHP? MySQL:将postid从一个表复制到同一数据库中的另一个表 - MySQL: Copy postid from one table to another in same database PHP / MySQL:将表和数据从一个数据库复制到另一个数据库 - PHP/MySQL: Copy Table and Data from one Database to another 使用php将数据库从服务器复制到服务器 - copy database from server to server with php 如何使用php将所有表从一个数据库复制到另一个数据库? - How to copy all the tables from one database to another database using php? 将表从一个数据库复制到另一个数据库,但使用不同的用户,在joomla中使用php - Copy tables from one database to another database but with different users, php in joomla PHP来自多个表,但在同一数据库中 - PHP results from multiple tables but in the same database 使用PDO将行从一个数据库中的表移至另一数据库 - Moving rows from tables in one database to another database using PDO 将数据库表从一台服务器发送到另一台服务器中的另一数据库表PHP MySQL - Send database table from one server to another database table in different server PHP MySQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM